今天在CentOS 6.5上安装mysql5.7时遇到一个问题,没有初始化密码。mysql
在mysql5.7以前的版本首次登录是无需密码的,可是5.7起会生成一个初始化密码/root/.mysql_secertsql
cat /root/.mysql_secert 就能够查看初始化密码了bash
可是个人安装没有发现.mysql_secert文件。ide
这种状况的解决方案:this
mysqld_safe --user=mysql --skip-grant-tables &
#跳过受权验证方式启动mysql
mysql -uroot -p
>use mysql;
>desc user;
#发现没有了password这个密码参数
...略
| 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 |
+-----------+-----------+-------------------------------------------+------------------+
#到这里不难发现root帐户的密码已过时,还比5.6多出了一个mysql.sys用户
>update user
set
authentication_string=password(
'123456'
) where user=
'root'
;
#修改密码为123456
>flush privileges;
从新登陆mysql,首先停掉全部mysql进程spa
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 修改密码,因此登录进来的第一件事情是修改mysql的初始密码。不然使用会报错
> alter user root@
'localhost'
identified by
'aolens123..'
;
#这下就行了code
能够看到5.7的密码字段改为了authentication_string,orm