新安装mysql,root密码设置问题

最近安装mysql5.6版本,在要建立数据库时发现root密码找不到了,这里有个疑问?初始密码不是为空的吗?后面找了资料才知道是这回事。

安装的过程中有这样的一句话:

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !

You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,

no other statement but 'SET PASSWORD' will be accepted.

See the manual for the semantics of the 'password expired' flag.

立马去查看下发现:

[root@localhost ~]# cat /root/.mysql_secret
# The random password set for the root user at Tue Jul 24 18:34:19 2018 (local time): CdLnCsWienBUG0YZ

真的是存在的。

通过初始密码进入后,通过下面命令修改密码:

MySQL -u root

  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

扩展知识,如果忘记密码也可以通过下面方法找回root密码。

先停止数据库:/etc/init.d/mysql stop

然后执行下面语句

mysqld_safe --skip-grant-tables&

  mysql -u root mysql

  mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

  mysql> FLUSH PRIVILEGES;

 

转载于:https://my.oschina.net/u/3833580/blog/1862750

你可能感兴趣的:(新安装mysql,root密码设置问题)