今天遇到兩個問題:Can’t connect to MySQL server 與 Access denied for user !

來源:互聯網
上載者:User

問題一:本機(localhost)串連一切正常,但是無法從其他電腦上登入 MySQL 資料庫!

下面是 /etc/mysql/my.cnf 中的一段摘錄:


# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 10.0.0.1 # 127.0.0.1

其中說明 MySQL預設設定為只在 localhost 進行偵聽,所以如果登入的 MySQL Client 與 MySQL Server 不為同一台電腦的話,MySQL 是不會響應的。故需要把這裡的 bind-address 修改為此台電腦的 external IP 即可。

問題二:ERROR 1045 (28000): Access denied for user 'root'@'10.0.0.1' (using password: YES) !

這個也是頗有意思,首先看看原本系統資料表中的資料:


mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> SELECT Host FROM user WHERE user='root';
+-----------+
| Host      |
+-----------+
| sharkwang |
| localhost |
+-----------+
2 rows in set (0.00 sec)

恩,這裡除了有 localhost 外,居然還有一個 sharkwang ,而我串連的時候是用IP而不是hostname !

所以,有2個方案:

1. 在 MySQL Client 所在的電腦上面,修改 /etc/hosts 檔案,加入 hostname 和 IP 的映射關係。

    登入方式為: shell> mysql -h <mysql_server_hostname> -u root -p

2. 在 MySQL 資料庫的 user 表中增加一條記錄,內容參照:

    SELECT * FROM user WHERE User='root' AND Host='localhost'

    然後把 Host 對應的值修改為 MySQL Server 的 external IP。

    登入方式為: shell> mysql -h <mysql_server_ip> -u root -p

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.