CentOS7安装MySQL5.7

这里使用yum的方式安装mysql5.7,仅为测试使用,生产环境中,还是建议使用cmake编译安装mysql

安装MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
> yum remove -y mysql
> cd /usr/local/src/
> wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
> rpm -ivh mysql57-community-release-el7-8.noarch.rpm
警告:mysql57-community-release-el7-8.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql57-community-release-el7-8 ################################# [100%]
> yum install -y mysql-server
> systemctl start mysqld
> systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2016-08-19 09:30:24 EDT; 29s ago
Process: 105136 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 105049 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 105138 (mysqld)
CGroup: /system.slice/mysqld.service
└─105138 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

8月 19 09:30:16 localhost.localdomain systemd[1]: Starting MySQL Server...
8月 19 09:30:24 localhost.localdomain systemd[1]: Started MySQL Server.
> cat /var/log/mysqld.log| grep "temporary password"
2016-08-19T13:30:20.547835Z 1 [Note] A temporary password is generated for root@localhost: TVu7ouUi>55l
> mysql -uroot -p
Enter password:TVu7ouUi>55l
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.14

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>

设置root用户密码

MySQL5.7默认的密码复杂度为:大小写字母+数字+特殊符号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mysql> alter user user() identified by 'w{YQW6L;Dsf6vw';
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_dictionary_file | |
| 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 |
+--------------------------------------+--------+
6 rows in set (0.01 sec)

mysql对于密码有3种检验策略,默认validate_password_policyMEDIUM

  • LOW policy tests password length only. Passwords must be at least 8 characters long.
  • MEDIUM policy adds the conditions that passwords must contain at least 1 numeric character, 1 lowercase and uppercase character, and 1 special (nonalphanumeric) character.
  • STRONG policy adds the condition that password substrings of length 4 or longer must not match words

在默认MEDIUM的策略下,修改密码为:12345678会报错

1
2
mysql> alter user user() identified by '12345678';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

修改MySQL密码检查策略

1
2
3
4
5
mysql> SET GLOBAL validate_password_policy = LOW;
Query OK, 0 rows affected (0.00 sec)

mysql> alter user user() identified by '12345678';
Query OK, 0 rows affected (0.00 sec)