溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

mysql5.7未生成初始密碼.mysql_secert文件,登陸數(shù)據(jù)庫

發(fā)布時(shí)間:2020-07-13 12:56:29 來源:網(wǎng)絡(luò) 閱讀:4018 作者:aolens 欄目:數(shù)據(jù)庫

今天在CentOS 6.5上安裝mysql5.7時(shí)遇到一個(gè)問題,沒有初始化密碼。

在mysql5.7之前的版本首次登陸是無需密碼的,但是5.7起會(huì)生成一個(gè)初始化密碼/root/.mysql_secert

cat /root/.mysql_secert 就可以查看初始化密碼了

但是我的安裝沒有發(fā)現(xiàn).mysql_secert文件。

 

這種情況的解決方案:

mysqld_safe --user=mysql --skip-grant-tables & #跳過授權(quán)驗(yàn)證方式啟動(dòng)mysql
 
mysql -uroot -p
 
>use mysql;
 
>desc user; #發(fā)現(xiàn)沒有了password這個(gè)密碼參數(shù)
...略
| 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 |
+-----------+-----------+-------------------------------------------+------------------+
#到這里不難發(fā)現(xiàn)root賬戶的密碼已過期,還比5.6多出了一個(gè)mysql.sys用戶
 
>update user set authentication_string=password('123456') where user='root';
#修改密碼為123456
 
>flush privileges;

重新登錄mysql,首先停掉所有mysql進(jìn)程

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.
#報(bào)錯(cuò),需要使用alter user 修改密碼,所以登陸進(jìn)來的第一件事情是修改mysql的初始密碼。否則使用會(huì)報(bào)錯(cuò)
 
> alter user root@'localhost' identified by 'aolens123..';

#這下就好了

可以看到5.7的密碼字段改成了authentication_string,



向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI