欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL登錄時出現(xiàn) Access denied for user ‘root‘@‘xxx.xxx.xxx.xxx‘ (using password: YES) 的原因及解決辦法

 更新時間:2024年03月11日 11:04:15   作者:zlfjavahome  
今天打開mysql的時候突然提示:Access denied for user 'root'@'localhost' (using password: YES) 在網(wǎng)上搜索了很多文章,本文就來做一下總結,介紹了幾種場景的解決方法,感興趣的可以了解一下

場景一:調試web程序訪問數(shù)據(jù)庫的時候出現(xiàn)

場景二:MySQL登陸的時候,區(qū)分本地localhost登陸,以及遠程登陸。即使本地能夠登陸,如果不授權也無法遠程登陸

分析原因:(區(qū)分)當本地出現(xiàn)這樣的情況,就是密碼錯誤,找到正確的密碼或者修改密碼;當遠程登陸的時候,首先確定登陸密碼是否正確,第二確定是否遠程授權。針對以上兩種情況,給出解決方案。

情況一解決方案:修改本地數(shù)據(jù)庫密碼

方法1: 用SET PASSWORD命令
首先登錄MySQL。
格式:mysql> set password for 用戶名@localhost = password('新密碼');
例子:mysql> set password for root@localhost = password('123');

方法2:用mysqladmin
格式:mysqladmin -u用戶名 -p舊密碼 password 新密碼
例子:mysqladmin -uroot -p123456 password 123

方法3:用UPDATE直接編輯user表
首先登錄MySQL。
mysql> use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
mysql> flush privileges;

方法4:在忘記root密碼的時候,可以這樣
以windows為例:

關閉正在運行的MySQL服務。

打開DOS窗口,轉到mysql\bin目錄。

輸入mysqld --skip-grant-tables 回車。--skip-grant-tables 的意思是啟動MySQL服務的時候跳過權限表認證。

再開一個DOS窗口(因為剛才那個DOS窗口已經(jīng)不能動了),轉到mysql\bin目錄。

輸入mysql回車,如果成功,將出現(xiàn)MySQL提示符 >。

連接權限數(shù)據(jù)庫: use mysql; 。

改密碼:update user set password=password("123") where user="root";(別忘了最后加分號) 。

刷新權限(必須步驟):flush privileges; 

退出 quit。

注銷系統(tǒng),再進入,使用用戶名root和剛才設置的新密碼123登錄。

情況二解決方案 :遠程授權

1. 先用localhost登錄(進入MySQL) mysql -u root -p

Enter password: (輸入密碼)
2. 執(zhí)行授權命令
mysql> grant all privileges on . to root@'%' identified by '123'; (注意語句后面的“;”)
Query OK, 0 rows affected (0.07 sec)
3. 退出再試: mysql> quit
4、再試登錄: mysql -u root -h 192.168.194.142 -p
Enter password:
結果顯示:Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
表示成功

下面詳細說說如何給用戶授權

mysql> grant 權限1,權限2, ... 權限n on 數(shù)據(jù)庫名稱.表名稱 to 用戶名@用戶地址 identified by '連接口令';

權限1,權限2,... 權限n 代表 select、insert、update、delete、create、drop、index、alter、grant、references、reload、shutdown、process、file 等14個權限。
當權限1,權限2,... 權限n 被 all privileges 或者 all 代替時,表示賦予用戶全部權限。
當 數(shù)據(jù)庫名稱.表名稱 被 . 代替時,表示賦予用戶操作服務器上所有數(shù)據(jù)庫所有表的權限。
用戶地址可以是localhost,也可以是IP地址、機器名和域名。也可以用 '%' 表示從任何地址連接。
'連接口令' 不能為空,否則創(chuàng)建失敗。

舉幾個例子:
mysql> grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對數(shù)據(jù)庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的權限,并設定口令為123。

mysql> grant all privileges on vtdc.* to joe@10.163.225.87 identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對數(shù)據(jù)庫vtdc所有表進行所有操作的權限,并設定口令為123。

mysql> grant all privileges on . to joe@10.163.225.87 identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對所有數(shù)據(jù)庫的所有表進行所有操作的權限,并設定口令為123。

mysql> grant all privileges on . to joe@localhost identified by ‘123′;
給本機用戶joe分配可對所有數(shù)據(jù)庫的所有表進行所有操作的權限,并設定口令為123。案:遠程授權

到此這篇關于MySQL登錄時出現(xiàn) Access denied for user ‘root‘@‘xxx.xxx.xxx.xxx‘ (using password: YES) 的原因及解決辦法的文章就介紹到這了,更多相關MySQL Access denied for user內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論