Centos7 mysql8.0 the installation and modification of the initial password;

First download the installation package mysql total of these types of
mysql-community-client.x86_64                 8.0.16-2.el7              
mysql-community-common.x86_64            8.0.16-2.el7               
mysql-community-libs.x86_64                    8.0.16-2.el7                  
mysql-community-libs-compat.x86_64       8.0.16-2.el7                 
mysql-community-server.x86_64               8.0.16-2.el7                   
mysql-connector-java.noarch                     1:5.1.25-3.el7                  
mysql-connector-odbc.x86_64                   5.2.5-6.el7
yum install mysqld
[root@xiaoyaoji ~]# yum -y install mysql-server
[root@xiaoyaoji ~]# vi /etc/my.cnf
##在最后一行添加skip-grant-tables
[root@xiaoyaoji ~]# systemctl start mysqld
[root@xiaoyaoji ~]# mysql -uroot -p
Enter password:                                                                  ## 直接回车
mysql> use mysql;                                                                ## 进入mysql表
mysql> update user set authentication_string='' where user='root';               ## 将密码设置为空(必须在mysql库设置)
mysql> quti
[root@xiaoyaoji ~]# vi /etc/my.cnf                                               ##将添加的skip那一行删除,然后重启服务;
[root@xiaoyaoji ~]# systemctl restart mysqld
[root@xiaoyaoji ~]# mysql -uroot -p
Enter password:                                                                  ##直接回车
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Root@123';    ##设置密码(密码要复杂一点,否指会报错)
mysql> exit
Next for authorization of mysql, mysql's host access authorization, otherwise not visit
[root@xiaoyaoji ~]# mysql -uroot -pRoot@123                                       ##尽量不要在命令行输入密码;
在mysql8.0中 授权语句已经更换,使用之前的sql语句授权会报错;
mysql> create user 'root'@'%' identified by 'Root@123';                           ##创建可以所有用户都可以访问的用户规则
mysql> grant all privileges on *.* to 'root'@'%';                                 ##对这个用户规则进行授权
mysql> flush privileges;                                                          ##刷新权限
mysql> exit

Guess you like

Origin blog.csdn.net/weixin_44691065/article/details/91891794