溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL 'root'@'localhost'無法登錄

發布時間:2020-09-22 19:17:18 來源:網絡 閱讀:2157 作者:Mr_sheng 欄目:MySQL數據庫

今天早上同事說MySQL root賬號登錄不上了。我試了一下 

#mysql -u root -p 

提示”Access denied for user ‘root’@’localhost’ (using password: YES)”


因為年后有同事離職,我第一反應是誰修改了root密碼?按照忘記root密碼來重置一下密碼: 

#/etc/init.d/mysql stop 

#mysqld_safe –skip-grant-tables & 

#mysql -uroot -p 

mysql>update mysql.user set password=password(‘mypassword’) where user=’root’; 

mysql>flush privileges; 

mysql>quit


用新密碼還是無法登錄,提示跟上面一樣。換一個非root賬號登錄,查看一下user表: 

mysql> select user,host from user; 

+———–+———+ 

| user   | host | 

+———–+———+ 

| root  | 127.0.0.1 | 

| night | % | 

+———–+———+


懷疑默認的localhost沒有映射到127.0.0.1?試試#mysql -u root -p xxxx -h 127.0.0.1,果然可以登錄。 

之前配置數據庫的同學沒有給’root’@’localhost’和’root’@’ip’授權。 

grant all privileges on . to ‘root’@’localhost’ identified by ‘mypassword’ with grant option; 

grant all privileges on . to ‘root’@’118.192.91.xxx’ identified by ‘mypassword’ with grant option;


再查詢一下用戶表: 

這里寫圖片描述 

MySQL 'root'@'localhost'無法登錄

然后#mysql -u root -p xxxx,登錄成功!


查了一下mysql -h localhost和mysql -h 127.0.0.1的區別,通過localhost連接到mysql是使用UNIX socket,而通過127.0.0.1連接到mysql是使用TCP/IP??纯礌顟B: 

mysql -h localhost > status 

Connection id:     639 

Current database: mysql 

Current user:   root@localhost 

SSL:           Not in use 

Current pager: stdout 

Using outfile:        ” 

Using delimiter:    ; 

Server version:     5.6.15-log Source distribution 

Protocol version: 10 

Connection:    Localhost via UNIX socket


mysql -h 127.0.0.1 > status 

Connection id:     640 

Current database: mysql 

Current user:   root@localhost 

SSL:           Not in use 

Current pager: stdout 

Using outfile:        ” 

Using delimiter:    ; 

Server version:     5.6.15-log Source distribution 

Protocol version: 10 

Connection:   127.0.0.1 via TCP/IP



向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女