centos 7 通过 yum 安装mysql 8.x

CentOS7使用yum安装MySQL8.x
# yum localinstall https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
# yum install mysql-community-server.x86_64

启动 mysql:

# systemctl start  mysqld.service

查看mysql 服务的运行状态
# systemctl status mysqld.service

mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-02-26 18:14:13 PST; 1h 10min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 22524 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 22670 (mysqld)
   Status: "SERVER_OPERATING"
   CGroup: /system.slice/mysqld.service
           └─22670 /usr/sbin/mysqld

Feb 26 18:14:00 localhost.localdomain systemd[1]: Starting MySQL Server...
Feb 26 18:14:13 localhost.localdomain systemd[1]: Started MySQL Server.
 

查看密码
[root@localhost run]#  grep 'password' /var/log/mysqld.log  
2019-02-27T02:14:06.098913Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: :pk;Sgz/U1(6

登陆mysql
$ mysql -uroot -p":pk;Sgz/U1(6"
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 13
Server version: 8.0.15

Copyright (c) 2000, 2019, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'qwer1234';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

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 'z?guwrBhH7p>';
Query OK, 0 rows affected (0.03 sec)

mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| 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)

修改密码策略(降低要求,这样就可以随意设置密码了)
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | ON    |
| 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.58 sec)
 

再次修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'qwer1234';
Query OK, 0 rows affected (0.03 sec)

可视化工具的登录授权:(如果授权不成功,请查看防火墙) mysql8 与 mysql5 授权语句不同。
操作完成上面的,现在还不能用可视化的客户端进行连接,需要我们进行授权:
mysql> use mysql;
mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

mysql> create user 'root'@'%' identified by 'qwer1234'; 
Query OK, 0 rows affected (0.04 sec)

mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
5 rows in set (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' ;
Query OK, 0 rows affected (0.01 sec)

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

mysql8密码加密方式的变更:

之前默认是mysql_native_password,现在改为caching_sha2_password。很多连接工具,像nivacat12,仍然使用默认的mysql_native_password,所以在连接的时候回报错:

1251:Client does not support authentication protocol requested by server; consider upgrading
MySQL client

此时需要将mysql.user表中的plugin字段修改下:
mysql> select host, user, plugin from user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'qwer1234' PASSWORD EXPIRE NEVER; 
Query OK, 0 rows affected (0.01 sec)
 

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'qwer1234';
Query OK, 0 rows affected (0.04 sec)
 

mysql>  select host, user, plugin from user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | mysql_native_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)
 

关闭防火墙并禁止启动

[root@localhost code]# systemctl stop firewalld.service 
[root@localhost code]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
 

参考:

https://www.cnblogs.com/brianzhu/p/8575243.html

https://blog.csdn.net/xinpengfei521/article/details/80403965

猜你喜欢

转载自blog.csdn.net/mxcai2005/article/details/87928727