mysql許可權登入問題 1045

2021-08-27 00:09:41 字數 2264 閱讀 2999

mysql

中使用root

使用者登入出現:

error 

1045

(28000

): access deniedforuser 

'root'

@'localhost'

(using password: yes)

錯誤產生的原因是

root

使用者沒有

localhost

登入的許可權,修改

/etc/my.cnf

資料庫配置檔案,在

[mysqld]

選項中新增:

skip-grant-tables   

使用安全模式登入

mysql

資料庫:

mysql –u root –p

(輸入密碼直接按回車,登入成功)。

mysql

資料庫中:

檢視mysql資料庫中user表中的資料:select user,host,password from mysql.user;

發現root使用者有127.0.0.1的許可權,沒有local host登入的許可權。

localhost和127.0.0.1登入是有區別的:

通過localhost登入資料庫是使用unix socket進行登入。

通過mysql –uroot –proot –h 127.0.0.1命令進行登入是使用tcp/ip協議進行登入。

因此在mysql.user表中新增root@localhost登入許可權。

grant all on *.* to 『root』@』localhost』;

檢視使用者表(select user,host,password from mysql.user;),發現此時使用者表中多了一條記錄,此時,password為空,與之前的root有密碼的[email protected]不是一回事。此時可以使用root@local host登入(空密碼)。修改root@localhost的密碼與[email protected]一致(使用update直接編輯mysql.user表):

update mysql.user set password=password(『root』) where user=』root』 and host=』localhost』;(修改一條記錄)

flush privileges;

或者:update mysql.user set password=password(『root』) where user=』root』;(同時修改兩條記錄)

flush privileges;

重新使用mysql –uroot –proot 成功登入。

如果使用grant all 無法設定某個使用者的許可權:

1、stop mysql的服務;

2、使用安全模式登入:vi /etc/my.cnf     在mysqld選項中新增 skip-grant-tables.

3、手動修改使用者的許可權,使其可以設定許可權。

update mysql.user set grant_priv=』y』,super_priv=』y』 where user=』root』;

4、重新整理緩衝區:flush privileges;

附:可以使用grant all on *.* to 『root』@』localhost』;給使用者許可權

select * from mysql.user\g  檢視使用者的許可權   \g表示豎行顯示。

service mysqld restart  重新啟動mysql。

windows中解除安裝mysql:1解除安裝程式 2刪除安裝的資料夾 3刪除proramdate隱藏資料夾中的mysql配置資料資料夾 4 刪除登錄檔中的mysql相關資訊。

centos下MySQL登入1045問題解決

由於需要在centos下部署整個應用,自然少不了對資料庫的操作。但很多人可能會遇到一些問題,比如建立使用者成功,但是卻無法登入。無法登陸一般就兩個原因。第一,遠端訪問埠沒開,第二個原因就是密碼錯誤了 很奇怪,我們登入時的密碼明明是正確的,但還是會提示密碼錯誤,我也不知道這是什麼原因,有可能是編碼之類...

mysql遠端登入許可權問題

遠端連線mysql資料庫的時候,報錯 出現 error 1130 hy000 host 192.168.14.1 is not allowed to connect to this mysql server提示資訊,不能遠端連線資料庫。解決方案如下 這個時候只要在localhost的那台電腦,登入m...

Mysql登入許可權問題 1130

在公司內網中使用電腦訪問另一台電腦上的mysql資料庫時,連線會出現1130的錯誤,錯誤原因是因為使用者沒有其他電腦登入本地資料庫的許可權,需要對資料庫中的使用者許可權進行修改 直接修改資料庫中的使用者表中的主機內容 use mysql update user set host where user...