MYSQL ERROR 1045 (28000): Access denied for user (using password: YES)

來源:互聯網
上載者:User

標籤:mysql   linux   

安裝mysql後,有的使用者既想在本地訪問,又想遠端存取。

mysql -h host -uroot -ppassword 出現錯誤:

MYSQL ERROR 1045 (28000): Access denied for user (using password: YES)

這是因為你沒有進入mysql的許可權,你的主機沒有在mysql的user表裡儲存,或者使用者名稱或者密碼不正確。

1.跳過授權,進入mysql:

mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

2.賦予足夠的許可權

grant all privileges on *.* to ‘root‘@‘%‘ with grant option;

將許可權匯入記憶體,可以不用重啟mysql來查看是否正確執行許可權

flush privileges;

3.重新設定使用者密碼

>use mysql

>UPDATE user SET Password=PASSWORD(‘newpassword‘) where USER=‘root‘;

4.sudo service mysql restart

成功。這樣就既可以從內網又可以從外網訪問資料庫了。

附:

如果user表裡沒有記錄,就得手動添加:

INSERT INTO user(host, user, password, select_priv, insert_priv, update_priv) VALUES (‘localhost‘, ‘username‘, PASSWORD(‘yourpassword‘), ‘Y‘, ‘Y‘,‘Y‘); 

注釋/etc/mysql/my.cnf裡的記錄

bind-address =127.0.0.1

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

MYSQL ERROR 1045 (28000): Access denied for user (using password: YES)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.