mysql.sock的作用


1、在編譯安裝mysql的時候,會將mysql的配置文件復制到/etc/my.conf中:

[root@Web-lnmp02 mysql]# cp support-files/my-small.cnf /etc/my.cnf 將配置模板復制到mysql的配置文件
cp:是否覆蓋"/etc/my.cnf"? y

2、可以通過查看/etc/my.conf查看mysql.sock的目錄位置:

復制代碼
[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:

復制代碼
[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> 
復制代碼

以下內容為轉載:http://jimingsong.iteye.com/blog/1418638

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM