Home >Database >Mysql Tutorial >【MySQL案例】mysql本机登录-S失效_MySQL

【MySQL案例】mysql本机登录-S失效_MySQL

WBOY
WBOYOriginal
2016-06-01 13:01:481340browse

1.1.1. mysql本机登录mysql时,-S参数失效

【环境描述】

mysql5.5.14

【问题描述】

配置了多实例

 

实例1

实例2

datadir

/home/mysql_3306

/home/mysql_3307

basedir

/usr

/usr

socket

/home/mysql_3306/mysq.sock

/home/mysql_3307/mysq.sock

登录实例2的时候,却连接到了实例1:

mysql -S /home/mysql_3307/mysql.sock

> show variables like '%sock%';

+---------------+-----------------------------+

| Variable_name | Value |

+---------------+-----------------------------+

| socket | /home/mysql_3306/mysql.sock |

+---------------+-----------------------------+

【问题原因】

mysql命令中的-S参数是用来指定unix_socket,但是此时mysql很明显没有使用socket。

查看/etc/my.cnf配置文件,发现[client]域配置如下:

[client]

host = 127.0.0.1

尝试修改host=localhost 和注释掉host,再次尝试登录mysql:

mysql -S /home/mysql_3307/mysql.sock

> show variables like '%sock%';

+---------------+-----------------------------+

| Variable_name | Value |

+---------------+-----------------------------+

| socket | /home/mysql_3307/mysql.sock |

+---------------+-----------------------------+

此时,正常登录上了指定的实例。

再次测试登录mysql:

mysql -S /home/mysql_3306/mysql.sock -h 127.0.0.1-P 3307

> show variables like '%sock%';

+---------------+-----------------------------+

| Variable_name | Value |

+---------------+-----------------------------+

| socket | /home/mysql_3307/mysql.sock |

+---------------+-----------------------------+

mysql登录的时候指定的socket是3306端口的,host是127.0.0.1,port是3307,登录后,连接的是3307端口的实例,

mysql -S /home/mysql_3307/mysql.sock -h127.0.0.1

> show variables like '%sock%';

+---------------+-----------------------------+

| Variable_name | Value |

+---------------+-----------------------------+

| socket | /home/mysql_3306/mysql.sock |

+---------------+-----------------------------+

mysql登录的时候指定的socket是3307端口的,host是127.0.0.1,port没有指定,登录后,连接的是3306端口的实例。

综上,mysql客户端连接mysql数据库的时候,如果同时指定了socket和host的时候,mysql会采用TCP/IP协议登录,此时socket会被忽略,默认情况下访问3306端口。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn