|
发表于 2007-6-2 00:39:12
|
显示全部楼层
把my.cnf中下面部分的socket改成一个新的文件名,比如:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock111
这时连接服务器会出现如下错误:
bumpy:/data1$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock111' (2)
现在用tcp连接看看。没有防火墙,应该可以连上。
bumpy:/data1$ mysql -u root --protocol tcp
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18 to server version: 4.1.15-Debian_1ubuntu5-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> quit;
Bye
并且有下面的连接记录:
bumpy:/data1$ cat /proc/net/ip_conntrack | grep 3306
tcp 6 106 TIME_WAIT src=127.0.0.1 dst=127.0.0.1 sport=38307 dport=3306 packets=8 bytes=471 src=127.0.0.1 dst=127.0.0.1 sport=3306 dport=38307 packets=5 bytes=355 [ASSURED] mark=0 use=1
加上如下防火墙规则:
bumpy:/data1$ sudo iptables -A INPUT -p tcp --dport 3306 -j DROP
再连:
bumpy:/data1$ mysql -u root --protocol tcp
此时连不上了。
恢复my.cnf回原状,再试:
bumpy:/data1$ mysql -u root --protocol tcp
用tcp还是连不上,用socket就又连上了。
bumpy:/data1$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20 to server version: 4.1.15-Debian_1ubuntu5-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> quit
Bye |
|