之前在CentOS上安装mysql-5.7的时候出现很多问题,这里总结一下。
首先去MYSQL官网下载mysql-5.7.15-1.el7.x86_64.rpm-bundle.tar(写本篇内容的时候是2016-09-20,后面mysql会有更新,不知道会不会有变化,不过当大家出现此类问题的时候也可以借此解决)。
把下载好的.tar包放到CentOS的某个目录下,例如/home/user/(user代表当前用户),然后解压
# tar xf mysql-5.7.11-1.el6.x86_64.rpm-bundle.tar
安装必须的组件
[ CPU控制 ]
#yum install numactl
[ 磁盘文件读写 ]
#yum install libaio
#yum install perl-Time-HiRes per-devel
安装mysql-community-server之前,必须安装mysql-community-client和mysql-community-common rpm包。而安装community-client和community-common包之前,必须删除mysql-lib(系统自带的版本过低)。
[ 查看是否有mysql ]
# rpm -qa | grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
[ 删除mysql以及相关信息 ]
# rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
上面卸载了mysql-lib旧的包,现在安装mysql-lib最新版的文件,这个包在rpm-bundle里面都有, 直接安装即可。
# ls
mysql-5.7.11-1.el6.x86_64.rpm-bundle.tar mysql-community-embedded-5.7.11-1.el6.x86_64.rpm mysql-commu
mysql-community-client-5.7.11-1.el6.x86_64.rpm mysql-community-embedded-devel-5.7.11-1.el6.x86_64.rpm mysql-commu
mysql-community-common-5.7.11-1.el6.x86_64.rpm mysql-community-libs-5.7.11-1.el6.x86_64.rpm
# rpm -ivh mysql-community-common-5.7.11-1.el6.x86_64.rpm
# rpm -ivh mysql-community-libs-5.7.11-1.el6.x86_64.rpm
# rpm -ivh mysql-community-client-5.7.11-1.el6.x86_64.rpm
# rpm -ivh mysql-community-server-5.7.11-1.el6.x86_64.rpm
# service mysql start
mysql: unrecognized service
[ mysql5.7的名称是mysqld ]
# service mysqld start
Initializing MySQL database: [ OK ]
Installing validate password plugin: [ OK ]
Starting mysqld: [ OK ]
[ netstat -tlunp 查看哪些端口占用 ]
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
[ 显示此信息则表示mysql服务启动 ]
tcp 0 0 :::3306 :::* LISTEN 19928/mysqld
rpm安装mysql后,会自动初始化一个密码,在日志中。
# grep "password" /var/log/mysqld.log
2016-03-11T01:44:23.093873Z 1 [Note] A temporary password is generated for root@localhost: 8%<rjn;+,11Y
可以看到系统初始化的密码是8%
但是由于最新的mysql版本对密码策略有要求,所以必须增加复杂程度才能通过。
# mysql -uroot -p
Enter password: 此处输入刚才日志文件中的随机密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.11
Copyright (c) 2000, 2016, 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的密码规则要求 ]
mysql> set password='Yes@126.com';
Query OK, 0 rows affected (0.15 sec)
[ 密码不符合要求 ]
mysql> set password='123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
提示当前密码不符合mysql的安全策略,这是因为我们的密码不满足mysql预设定的强度,密码强度可由validate password strength()函数评估(返回0至100之间的数),如:
[ 密码强度25 ]
mysql> select VALIDATE_PASSWORD_STRENGTH('123456');
+--------------------------------------+
| VALIDATE_PASSWORD_STRENGTH('123456') |
+--------------------------------------+
| 25 |
+--------------------------------------+
1 row in set (0.00 sec)
这个强度其实与validate_password_policy的值有关。
validate_password_policy有以下取值:
Policy | Tests Performed |
---|---|
0 or LOW | Length |
1 or MEDIUM | Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG | Length; numeric, lowercase/uppercase, and special characters; dictionary file |
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
在进行一下步骤的时候,需要validate_password插件必须已经安装,MySQL5.7是默认安装的。 那么如何验证validate_password插件是否安装呢?可通过查看以下参数,如果没有安装,则输出将为空。
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_dictionary_file | |
| validate_password_length | 5 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 2 |
+--------------------------------------+-------+
6 rows in set (0.18 sec)
有时候,只是为了自己测试,不想密码设置得那么复杂,譬如说,我只想设置root的密码为123456。
必须修改两个全局参数:
首先,修改validate_password_policy参数的值
mysql> select VALIDATE_PASSWORD_STRENGTH('1');
+---------------------------------+
| VALIDATE_PASSWORD_STRENGTH('1') |
+---------------------------------+
| 0 |
+---------------------------------+
1 row in set (0.00 sec)
这样,判断密码的标准就基于密码的长度了。这个由validate_password_length参数来决定。
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 8 |
+----------------------------+
1 row in set (0.00 sec)
validate_password_length参数默认为8,它有最小值的限制,最小值为:
validate_password_length =
validate_password_number_count
+ validate_password_special_char_count
+ (2 * validate_password_mixed_case_count)
其中,validate_password_number_count指定了密码中数据的长度,validate_password_special_char_count指定了密码中特殊字符的长度,validate_password_mixed_case_count指定了密码中大小字母的长度。
这些参数,默认值均为1,所以validate_password_length最小值为4,如果你显性指定validate_password_length的值小于4,尽管不会报错,但validate_password_length的值将设为4。如下所示:
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 4 |
+----------------------------+
1 row in set (0.00 sec)
如果修改了 validate_password_number_count
validate_password_special_char_count
validate_password_mixed_case_count中任何一个值,则validate_password_length将进行动态修改。
mysql> select @@validate_password_mixed_case_count;
+--------------------------------------+
| @@validate_password_mixed_case_count |
+--------------------------------------+
| 1 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> select @@validate_password_special_char_count;
+----------------------------------------+
| @@validate_password_special_char_count |
+----------------------------------------+
| 1 |
+----------------------------------------+
1 row in set (0.00 sec)
mysql> select @@validate_password_number_count;
+----------------------------------+
| @@validate_password_number_count |
+----------------------------------+
| 1 |
+----------------------------------+
1 row in set (0.00 sec)
下面修改三个值中的一个
mysql> select @@validate_password_number_count;
+----------------------------------+
| @@validate_password_number_count |
+----------------------------------+
| 1 |
+----------------------------------+
1 row in set (0.00 sec)
mysql> set global validate_password_special_char_count=2;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@validate_password_special_char_count;
+----------------------------------------+
| @@validate_password_special_char_count |
+----------------------------------------+
| 2 |
+----------------------------------------+
1 row in set (0.00 sec)
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 5 |
+----------------------------+
1 row in set (0.00 sec)
现在再来修改密码(经过刚才的设置,密码可以不含有特殊字符,不过最少要五位)。
mysql> set password="123456";
Query OK, 0 rows affected (0.00 sec)
mysql> set password="1234";
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements