centos mysql5.7安装

1. 安装

1 wget http://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
2 rpm -ivh mysql57-community-release-el7-11.noarch.rpm 
3 yum install -y mysql-community-server

2. 验证安装

1 mysqladmin --version
mysqladmin  Ver 8.42 Distrib 5.7.27, for Linux on x86_64

3. 启动mysql

1 systemctl start mysqld
2 systemctl enable mysqld        #设为开机启动

  查看状态

1 systemctl status mysqld

 4. 首次登陆

  获取初始密码

1 grep "password" /var/log/mysqld.log 
2019-10-09T05:38:13.539819Z 1 [Note] A temporary password is generated for root@localhost: yUFwLSCMW5!q

  登陆

1 mysql -uroot -p
Enter password:     #输入密码即可登陆

5. 修改密码

1 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';    #修改密码为"root123"
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements    
#密码不符合策略

  查看密码策略

1 mysql> SHOW VARIABLES LIKE 'validate_password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.    
#先改密码才行

  修改密码(长度8位以上,包含大小写,特殊字符,)

1 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password_123';
Query OK, 0 rows affected (0.00 sec)

  再查看(默认)密码策略

1 mysql>  SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |    #OFF密码可以等于用户名,ON密码不能等于用户名
| validate_password_dictionary_file    |        |    #密码策略文件(检查强度为STRONG时需要)
| validate_password_length             | 8      |    #密码最小长度
| validate_password_mixed_case_count   | 1      |    #至少包含大/小写字母的总个数;
| validate_password_number_count       | 1      |    #至少包含数字个数
| validate_password_policy             | MEDIUM |    #检查强度等级
| validate_password_special_char_count | 1      |    #至少包含的特殊字符个数
+--------------------------------------+--------+
7 rows in set (0.01 sec)
注:
#密码最小长度为:validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
#检查强度等级:
  0或LOW:只检查长度;
  1或MEDIUM:检查长度,数字,大小写,特殊字符;
  2或STRONG:检查长度,数字,大小写,特殊字符和文件

  修改密码策略

1 mysql> SET GLOBAL validate_password_length=4;      #修改密码最小长度为4
2 mysql> SET GLOBAL validate_password_policy=LOW;    #修改检查强度为LOW
3 mysql> FLUSH PRIVILEGES;                     

  查看当前密码策略

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

  修改密码为'root123'

1 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
2 mysql> FLUSH PRIVILEGES;

6.设置远程登录

1 mysql> use mysql
2 mysql> SELECT user,host FROM user WHERE user='root';
+------+-----------+
| user | host      |
+------+-----------+
| root | localhost |    #只允许本机登录
+------+-----------+
1 row in set (0.00 sec)
1 mysql> UPDATE user SET host='%' WHERE user='root';
2 mysql> SELECT user,host FROM user WHERE user='root';
+------+------+
| user | host |
+------+------+
| root | %    |    
+------+------+
1 row in set (0.00 sec)
1 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root123' WITH GRANT OPTION;     #授权
2 mysql> FLUSH PRIVILEGES;

  远程连不上可以尝试关闭防火墙。

posted @ 2019-10-09 14:52  故道丶白云  阅读(158)  评论(0编辑  收藏  举报