1 、在编译安装 mysql 的时候,会将 mysql 的配置档案复制到/etc/my.conf 中:
[root@Web-lnmp02 mysql]# cp support-files/my-small.cnf /etc/my.cnf 将配置 WordPress 模板复制到 mysql 的配置档案
cp:是否覆盖”/etc/my.cnf”? y
2 、可以通过检视/etc/my.conf 检视 mysql.sock 的目录位置:
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@mysql ~]# cat /etc/my.cnf
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
3 、在登入 mysql 的时候可以加上 mysql.sock:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@mysql ~]# mysql -u root -poldboy123 -S /tmp/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.
mysql>
Mysql 有两种连线方式:
(1)TCP/IP
(2)socket
对 mysql.sock 来说,其作用是程式与 mysqlserver 处于同一台机器,发起本地连线时可用。
例如你无须定义连线 host 的具体 IP 地址,只要为空或 localhost 就可以。 在此种情况下,即使你改变 mysql 的外部 port 也是一样可能正常连线。
因为你在 my.ini 中或 my.cnf 中改变埠后,mysql.sock 是随每一次 mysql server 启动生成的。已经根据你在更改完 my.cnf 后重启 mysql 时重新生成了一次,资讯已跟著变更。 那么对于外部连线,必须是要变更 port 才能连线的。 linux 下安装 mysql 连线的时候经常回提示说找不到 mysql.sock 档案,解决办法很简单: 如果是新安装的 mysql,提示找不到档案,就搜寻下,指定正确的位置。 如果 mysql.sock 档案误删的话,就需要重启 mysql 服务,如果重启成功的话会在 datadir 目录下面生成 mysql.sock 到时候指定即可。 如果还不行就选择用 TCP 连线方式连线就行了,其实 windows 下还支援管道连线方式。