环境:Ubuntu 12.04 LTS


允许 MySQL 以 root 用户远程登陆

初始情况下,是这样的

$ mysql -u root -h 10.10.10.3 -p
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on '10.10.10.3' (111)



C.5.2.2 Can't connect to [local] MySQL server

If the server was started with --skip-networking, it will not accept TCP/IP connections at all. If the server was started with --bind-address=127.0.0.1, it will listen for TCP/IP connections only locally on the loopback interface and will not accept remote connections.

修改 /etc/mysql/my.cnf:

bind-address            = 127.0.0.1

换成

bind-address            = 0.0.0.0


修改完之后,还是连接不上:


$ mysql -u root -h 10.10.10.3 -p
Enter password: 
ERROR 1130 (HY000): Host 'ubuntu2.novalocal' is not allowed to connect to this MySQL server


mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '<password_for_root>';

现在就可以连接上了!



关于 MySQL 的链接方式

A MySQL client on Unix can connect to the mysqld server in two different ways: By using a Unix socket file to connect through a file in the file system (default /tmp/mysql.sock), or by using TCP/IP, which connects through a port number. A Unix socket file connection is faster than TCP/IP, but can be used only when connecting to a server on the same computer. A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost.