关于MySQL5.6版本使用随机密码初次登陆问题

最近在安装MySQL 5.6 版本后发现,使用空密码无法登陆。

MySQL在安装后生成了一个随机的密码,可以在 '/root/.mysql_secret’中找到。

查看随机密码

[root@node01 usr]# more /root/.mysql_secret
# The random password set for the root user at Tue Dec 10 19:17:01 2019 (local time): ebVNjLNSgNdM4Hvn

重启MySQL

service mysql restart

登陆MySQL

[root@node01 usr]# mysql -uroot -pebVNjLNSgNdM4Hvn
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.25

Copyright (c) 2000, 2015, 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> 

初次登陆后需要修改密码才可以执行SQL语句进行操作。

修改密码

mysql> set password=password('root');
Query OK, 0 rows affected (0.00 sec)

修改密码后可以正常执行SQL语句

mysql> select 1;
 
+---+
 
| 1 |
 
+---+
 
| 1 |
 
+---+
 
1 row in set (0.03 sec)
 
 
mysql>  

设置远程root访问

mysql> use mysql;  
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";    //为root添加远程连接的能力  
mysql> flush privileges;  
mysql> exit

至此,你就可以使用Navicat等工具连接啦。

发布了68 篇原创文章 · 获赞 4 · 访问量 7373

猜你喜欢

转载自blog.csdn.net/weixin_44455388/article/details/103495112