安裝好mysql后,想使用另一個電腦進行遠程登錄,在登錄時 提示拒絕連接
百度后,發現需要兩個步驟解決該問題
- /etc/mysql/my.cnf 里修改bind_address = 0.0.0.0
- 進行授權
(1)直接授權
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; mysql>FLUSH RIVILEGES;
(2)改表法 可能是你的帳號不允許從遠程登陸,只能在localhost。這個時候只要在localhost的那台電腦,登入mysql后,更改 “mysql” 數據庫里的 “user” 表里的 “host” 項,從”localhost”改成”%”
mysql -u root -p passwd mysql>use mysql; mysql>update user set host = '%' where user = 'root'; mysql>select host, user from user;
但是在進行第一步的時候,my.cnf里的內容卻是如下這樣的:
# # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/
最后發現,需要修改 的是 /etc/mysql/mysql.conf.d/mysqld.cnf
使用sudovim /etc/mysql/mysql.conf.d/mysqld.cnf
修改bind_address = 0.0.0.0
然后重啟mysql服務即可: sudo /etc/init.d/mysql restart
