Centos Mysql安装及入门

0、背景

有一些知识很简单,很低频,但是偶尔还是需要使用,故而需要记下来。

开始的时候碰见mysql.sock文件找不到了,不知道什么时候被破坏了,修复了好久,问题一个接着一个,需要急着用,很浪费时间,所以直接选择重装。简单暴力有效。

 

1、安装

yum安装mysql

# 下载mysql源
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

# 添加mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm

# 安装mysql
yum install mysql-community-server

检查mysql源是否安装成功

# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                 141
mysql-tools-community/x86_64      MySQL Tools Community                      105
mysql57-community/x86_64          MySQL 5.7 Community Server                 404

 

2、启动

然后就是启动服务

systemctl start mysqld

到这里算是安装、启动完成了

验证下,有下面这个进程,差不多就说明ok了。

# ps -ef | grep mysql
mysql    31427     1  9 10:19 ?        00:16:14 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

 

3、初始密码

安装完mysql,有一个初始密码,在/var/log/mysqld.log文件中,找到下面这个位置,例如:

[Note] A temporary password is generated for root@localhost: VVwAk;E6y/6a

这里,VVwAk;E6y/6a 就是我的初始密码了,每个人的不一样。

 

4、修改初始密码

初始密码太复杂,一般都需要修改下。先用初始密码登入:

# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

这里插播一个错误

一般修改密码用这个命令就可以了。

# mysqladmin -u root -p password "abc123"
Enter password:

// 这里abc123是新密码,Enter password:地方输入原密码

但是,新密码强度太弱,不允许设置简单密码,报错信息如下

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin: unable to change password; error: 'Your password does not satisfy the current policy requirements'

所以,需要降低下密码强度的配置

 

 

5、降低初始密码强度配置

# mysql -u root -pXXXXXXX
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.29

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_mixed_case_count=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_special_char_count=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

上面最查看时有个错误,意思是需要重设密码,继续如下:(设置新密码为123456)

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 3     |
| validate_password_mixed_case_count   | 0     |
| validate_password_number_count       | 3     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 0     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

mysql> exit

OK,到这里密码重新设置完成

 

6、远程登入配置

mysql允许远程连接的命令就如下2条

mysql> grant all on *.* to root@'%' identified by '123456' with grant option; 
mysql> flush privileges;

执行效果如下

# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> grant all on *.* to root@'%' identified by '123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit

好了,到这里就可以愉快的使用MySQL了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章