CentOS7 installation MySQL8 Change Password

1. Add the local source of MySQL8

  • Execute the following command for installation MySQL source
[root@virde ~]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
[root@virde ~]# sudo yum localinstall mysql80-community-release-el7-1.noarch.rpm 
  • You can use the following command to check if the source added successfully
[root@virde ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql80-community/x86_64          MySQL 8.0 Community Server                  17

2. Install the MySQL server

  • Execute the following command to install
[root@virde ~]# sudo yum install mysql-community-server

There interrogation installation process input y carriage return.

Start MySQL

  • Start MySQL with the following command
[root@virde ~]# sudo service mysqld start
Starting mysqld:[ OK ]
  • You can check the status of MySQL with the following command
[root@virde ~]# sudo service mysqld status
mysqld (pid 3066) is running.
  • Restart MySQL
[root@virde ~]# sudo service mysqld restart
Starting mysqld:[ OK ]
  • Stop MySQL
[root@virde ~]# sudo service mysqld stop
Starting mysqld:[ OK ]

Note: If your server memory is 500M or less, may be due to insufficient memory lead to not start successfully.
The modified /etc/my.cnf innodb_buffer_pool_size = 50M to or less

MySQL ROOT account permissions configuration and remote link

Local Shell landed MySQL client, and modify the initial root password

  • After the software is installed, it will generate an initial password for a super user in the error log, you can view the initial password with the following command
[root@virde ~]# sudo grep 'temporary password' /var/log/mysqld.log
2018-04-27T05:20:28.645777Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: nDjEy-#jv7Dn
  • Landing mysql shell client, modify the initial password with the ALTER USER command
[root@virde ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, 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> flush privileges;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; Query OK, 0 rows affected (0.08 sec) 

Note: MySQL has certain requirements (new version allows you to modify the rules), the default password of password complexity rules are as follows:

  1. Length of not less than 8
  2. It must contain at least one number, one lowercase letter, one uppercase letter and one special character

Changing the root account remote access

  • Execute the following command to modify
mysql> use mysql;
mysql> update user set host="%" where user='root'; mysql> GRANT ALL ON *.* TO 'root'@'%'; mysql> flush privileges; 

After executing client from the shell with the exit command, restart MySQL.
Then you can test the client what the link is normal.

Requires attention to several issues

    1. GRANT statement above and may be different from previous versions, I have been an error in the wording used in previous versions. Other people write old-line tutorial This statement is not suitable for use in MySQL8 in. Cited in the latest document can be used to refer to the official website

    2. 有些系统会因为服务器防火墙导致即使配置成功,也无法远程链接MySQL。如果无法链接,可以先暂时关闭防火墙测试一下是否时因为防火墙的原因(不同版本的Centos系统防火墙配置可能不一样,具体可能需要另查资料)
      防火墙命令:
      [root@virde ~]# service firewalld stop
      或者
      [root@virde ~]# systemctl stop firewalld.service

    3. 如果你的客户端出现下面这个错误,Client does not support authentication protocol requested by server。是因为MySQL8服务器版本中使用了新的密码验证机制,这需要客户端的支持,如果是旧的客户端(比如Navicat for mysql 11.1.13),可能不会很好的支持,需要你换到比较新的版本。暂时没有找到能让旧版本支持的方法。引用链接中方法我试过了,不管用。

Guess you like

Origin www.cnblogs.com/z3286586/p/11527318.html