今天在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