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 下還支援管道連線方式。