yum源安装

下载并安装mysql官方的yum repository

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server

mysql数据库设置

启动mysql

systemctl start mysqld.service

查看mysql的运行状态

[root@localhost hbk]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2019-04-28 10:02:17 CST; 28s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 12367 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 12278 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 12371 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─12371 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

4月 28 10:02:02 localhost systemd[1]: Starting MySQL Server...
4月 28 10:02:17 localhost systemd[1]: Started MySQL Server.

要想进入mysql终端控制台,还需要找到mysql的root密码。

[root@localhost hbk]# grep "password" /var/log/mysqld.log 
2019-04-28T02:02:09.359964Z 1 [Note] A temporary password is generated for root@localhost: l:8mH4,#5h=w

进入mysql控制终端,把mysql的root密码改掉。

mysql> alter user 'root'@'localhost' identified by 'huangbaokang';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

如果在修改密码的时候报了如上错误,原因是你设置mysql的密码强度要求不符。跟validate_password_policy的值有关。
想查看一下这个变量的值也不行,哈哈,你必须先改个复杂点的密码才行。

mysql> show variables like 'validate_password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'huang123!ABC';
Query OK, 0 rows affected (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             | 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_length决定的,而validate_password_length的计算公式是:

validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)

密码规则一般我们不需要变动,服务器设置一个高强度的密码有利于安全的防护,不过也可以如下进行更改密码规则。

mysql > set global validate_password_policy=0;
mysql > set global validate_password_length=1;

设置如上就可以把密码设置成诸如1234之类的。

禁止yum自动更新

yum -y remove mysql57-community-release-el7-10.noarch

mysql客户端连接问题,一般是授权问题或者防火墙等问题。

grant all on *.* to root@'%' identified by '数据库密码';
flush privileges;