今天在CentOS 6.5上安装mysql5.7时遇到一个问题,没有初始化密码。
在mysql5.7之前的版本首次登陆是无需密码的,但是5.7起会生成一个初始化密码/root/.mysql_secert
cat /root/.mysql_secert 就可以查看初始化密码了
但是我的安装没有发现.mysql_secert文件。
这种情况的解决方案:
mysqld_safe --user=mysql --skip-grant-tables &
mysql -uroot -p
>use mysql;
>desc user;
...略
| authentication_string | text | YES | | NULL | |
| password_expired | enum(
'N'
,
'Y'
) | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum(
'N'
,
'Y'
) | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
>
select
user,host,authentication_string,password_expired from user;
+-----------+-----------+-------------------------------------------+------------------+
| user | host | authentication_string | password_expired |
+-----------+-----------+-------------------------------------------+------------------+
| root | localhost | *9AA01F6E2A80A823ACB72CC07337E2911404B5B8 | Y |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N |
+-----------+-----------+-------------------------------------------+------------------+
>update user
set
authentication_string=password(
'123456'
) where user=
'root'
;
>flush privileges;
重新登录mysql,首先停掉所有mysql进程
mysqld_safe --user=mysql &
mysql -uroot -p
>show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
> alter user root@
'localhost'
identified by
'aolens123..'
;
#这下就好了
可以看到5.7的密码字段改成了authentication_string,