1. 程式人生 > >Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'的解決

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'的解決

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]    $$$:以下選項會被MySQL客戶端應用讀取.

port        = 3306
socket    = /var/run/mysqld/mysqld.sock    $$$:用於本地連線的Unix套接字檔案

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket        = /var/run/mysqld/mysqld.sock    $$$:用於本地連線的Unix套接字檔案

nice        = 0    $$$:使用nice程式根據給定值來設定伺服器的排程優先順序

[mysqld]    $$$:MySQL 辦事端
#
# * Basic Settings
#

#
# * IMPORTANT
#   If you make changes to these settings and your system uses apparmor, you may
#   also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#

user        = mysql
socket        = /var/run/mysqld/mysqld.sock    $$$:為MySQL客戶程式與伺服器之間的本地通訊指定一個套接字檔案

port        = 3306    $$$:指定MsSQL偵聽的埠
basedir        = /usr    $$$:使用該目錄作為根目錄(安裝目錄)。
datadir        = /var/lib/mysql   $$$:從該目錄讀取資料庫檔案
tmpdir        = /tmp
skip-external-locking
skip-name-resolve    $$$:禁止MySQL對外部連線進行DNS解析,使用這一選項可以消除MySQL進行DNS解析的時間。但需要注意,如果開啟該選項,則所有遠端主機連線授權都要使用IP地址方式,否則MySQL將無法正常處理連線請求!
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address        = 127.0.0.1
#
# * Fine Tuning
#
key_buffer        = 16M    $$$:key_buffer是用於索引塊的緩衝區大小,增加它可得到更好處理的索引(對所有讀和多重寫)。對於記憶體在4GB左右的伺服器該引數可設定為256M或384M。注意:該引數值設定的過大反而會是伺服器整體效率降低!
max_allowed_packet    = 16M    $$$:包或任何生成的/中間字串的最大大小。
thread_stack        = 192K
thread_cache_size       = 8    $$$:快取可重用的執行緒數
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP    $$$:儲存引擎MyISAM設定為恢復模式。該選項值是DEFAULT、BACKUP、FORCE或QUICK值的任何組合.
#max_connections        = 100    $$$:MySQL伺服器同時處理的資料庫連線的最大數量(預設設定是100)。超過限制後會報 Too many connections 錯誤
#table_cache            = 64    $$$:為所有執行緒開啟表的數量。增加該值能增加mysqld要求的檔案描述符的數量。可以避免頻繁的開啟資料表產生的開銷
#thread_concurrency     = 10    $$$:最大併發執行緒數,取值為伺服器邏輯CPU數量×2,如果CPU支援H.T超執行緒,再×2
#
# * Query Cache Configuration
#
query_cache_limit    = 10M    $$$:只有小於此設定值的結果才會被緩衝,此設定用來保護查詢緩衝,防止一個極大的結果集將其他所有的查詢結果都覆蓋.
query_cache_size        = 160M    $$$:指定MySQL查詢結果緩衝區的大小
open_files_limit    = 2048    $$$:用來更改mysqld檔案描述符的數量
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1

log_error                = /var/log/mysql/error.log    $$$:將錯誤日誌寫入給定的檔案


# Here you can see queries with especially long duration
#log_slow_queries    = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id        = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10    $$$:二進位制日誌自動刪除的天數。預設值為0,表示“沒有自動刪除”。啟動時和二進位制日誌迴圈時可能刪除。
max_binlog_size         = 100M    $$$:如果二進位制日誌寫入的內容超出給定值,日誌就會發生滾動。你不能將該變數設定為大於1GB或小於4096位元組。 預設值是1GB。
#binlog_do_db        = include_database_name
#binlog_ignore_db    = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



[mysqldump]    $$$:轉儲存資料庫的實用程式

quick
quote-names
max_allowed_packet    = 16M    $$$:伺服器和客戶端之間最大能傳送的可能資訊包

[mysql]
#no-auto-rehash    # faster start of mysql but no tab completition

[isamchk]    $$$:完成表的分析和優化,以及在表損壞時進行崩潰恢復的程式。
key_buffer        = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/