无法摆脱:错误 2002 (HY000):无法通过套接字“/var/run/mysqld/mysqld.sock”连接到本地 MySQL 服务器 (2)

无法摆脱:错误 2002 (HY000):无法通过套接字“/var/run/mysqld/mysqld.sock”连接到本地 MySQL 服务器 (2)

我知道这里有很多这样的问题,但我没有找到我的问题的答案。

我有一台运行着几个网站和几个数据库的生产服务器。我遇到了一些性能问题,因此我编辑了 mysqld.cnf 文件,然后尝试重新启动 Mysql,但出现了错误:

Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

那里看不到任何具体细节。所以我尝试运行:mysql然后收到以下错误消息:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

在更改 mysqld.cnf 之前,我已经替换了所有默认设置,但仍然出现相同的错误。

我还检查了是否有任何 mysql 服务正在运行,但没有。而且/var/run/mysqld/文件夹是空的。我尝试在那里创建一些具有相应名称的空文件,但没有成功。

这里的问题是什么?我该如何安全地恢复它?我的网站目前处于离线状态...

编辑1-mysqld.cnf:

#
# 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.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[client]
socket=/var/run/mysqld/mysqld.sock

[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = localhost
#
# * Fine Tuning
#
key_buffer_size     = 16M
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-options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
#query_cache_limit  = 1M
#query_cache_size        = 16M
query_cache_type = 1
query_cache_limit = 256K
query_cache_min_res_unit = 2k
query_cache_size = 80M

#
# * 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
#
# Error log - should be very few entries.
#
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
max_binlog_size   = 100M
#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
innodb_buffer_pool_size = 4G # (adjust value here, 50%-70% of total RAM)
innodb_log_file_size = 128M

编辑 2:- 错误消息

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Wed 2017-11-15 15:41:40 CET; 20s ago
  Process: 15879 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 15871 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 15879 (code=exited, status=1/FAILURE);         : 15880 (mysql-systemd-s)
    Tasks: 2
   Memory: 344.0K
      CPU: 305ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─15880 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─15933 sleep 1

错误日志:

2017-11-15T15:05:16.045938Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-11-15T15:05:16.046016Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-11-15T15:05:16.201843Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-15T15:05:16.202956Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.18-0ubuntu0.16.04.1) starting as process 20323 ...
2017-11-15T15:05:16.207200Z 0 [Note] InnoDB: PUNCH HOLE support available
2017-11-15T15:05:16.207231Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-15T15:05:16.207237Z 0 [Note] InnoDB: Uses event mutexes
2017-11-15T15:05:16.207242Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2017-11-15T15:05:16.207248Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2017-11-15T15:05:16.207253Z 0 [Note] InnoDB: Using Linux native AIO
2017-11-15T15:05:16.207509Z 0 [Note] InnoDB: Number of pools: 1
2017-11-15T15:05:16.207622Z 0 [Note] InnoDB: Using CPU crc32 instructions
2017-11-15T15:05:16.209148Z 0 [Note] InnoDB: Initializing buffer pool, total size = 4G, instances = 8, chunk size = 128M
2017-11-15T15:05:16.468993Z 0 [Note] InnoDB: Completed initialization of buffer pool
2017-11-15T15:05:16.507282Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2017-11-15T15:05:16.519181Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2017-11-15T15:05:16.622208Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2017-11-15T15:05:16.622289Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2017-11-15T15:05:16.655372Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2017-11-15T15:05:16.656333Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2017-11-15T15:05:16.656352Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2017-11-15T15:05:16.656693Z 0 [Note] InnoDB: Waiting for purge to start
2017-11-15T15:05:16.706890Z 0 [Note] InnoDB: 5.7.18 started; log sequence number 66730045680
2017-11-15T15:05:16.707227Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2017-11-15T15:05:16.707400Z 0 [Note] Plugin 'FEDERATED' is disabled.
2017-11-15T15:05:16.707618Z 0 [Note] InnoDB: Buffer pool(s) load completed at 171115 16:05:16
2017-11-15T15:05:16.710592Z 0 [ERROR] unknown variable 'log_slow_queries=/var/log/mysql/mysql-slow.log'
2017-11-15T15:05:16.710608Z 0 [ERROR] Aborting

2017-11-15T15:05:16.710615Z 0 [Note] Binlog end
2017-11-15T15:05:16.710657Z 0 [Note] Shutting down plugin 'validate_password'
2017-11-15T15:05:16.710669Z 0 [Note] Shutting down plugin 'ngram'
2017-11-15T15:05:16.710673Z 0 [Note] Shutting down plugin 'ARCHIVE'
2017-11-15T15:05:16.710677Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2017-11-15T15:05:16.710681Z 0 [Note] Shutting down plugin 'partition'
2017-11-15T15:05:16.710684Z 0 [Note] Shutting down plugin 'MyISAM'
2017-11-15T15:05:16.710694Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2017-11-15T15:05:16.710698Z 0 [Note] Shutting down plugin 'CSV'
2017-11-15T15:05:16.710702Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2017-11-15T15:05:16.710735Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2017-11-15T15:05:16.710739Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2017-11-15T15:05:16.710742Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2017-11-15T15:05:16.710745Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2017-11-15T15:05:16.710749Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2017-11-15T15:05:16.710752Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2017-11-15T15:05:16.710755Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2017-11-15T15:05:16.710758Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2017-11-15T15:05:16.710762Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2017-11-15T15:05:16.710765Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2017-11-15T15:05:16.710768Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2017-11-15T15:05:16.710771Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2017-11-15T15:05:16.710774Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2017-11-15T15:05:16.710777Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2017-11-15T15:05:16.710781Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2017-11-15T15:05:16.710784Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2017-11-15T15:05:16.710787Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2017-11-15T15:05:16.710790Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2017-11-15T15:05:16.710793Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2017-11-15T15:05:16.710796Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2017-11-15T15:05:16.710799Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2017-11-15T15:05:16.710802Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2017-11-15T15:05:16.710805Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2017-11-15T15:05:16.710809Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2017-11-15T15:05:16.710822Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2017-11-15T15:05:16.710826Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2017-11-15T15:05:16.710830Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2017-11-15T15:05:16.710833Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2017-11-15T15:05:16.710836Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2017-11-15T15:05:16.710839Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2017-11-15T15:05:16.710842Z 0 [Note] Shutting down plugin 'InnoDB'
2017-11-15T15:05:16.710893Z 0 [Note] InnoDB: FTS optimize thread exiting.
2017-11-15T15:05:16.711042Z 0 [Note] InnoDB: Starting shutdown...
2017-11-15T15:05:16.811280Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2017-11-15T15:05:16.811522Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 171115 16:05:16
2017-11-15T15:05:18.415398Z 0 [Note] InnoDB: Shutdown completed; log sequence number 66730045699
2017-11-15T15:05:18.417886Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2017-11-15T15:05:18.417914Z 0 [Note] Shutting down plugin 'MEMORY'
2017-11-15T15:05:18.417924Z 0 [Note] Shutting down plugin 'sha256_password'
2017-11-15T15:05:18.417930Z 0 [Note] Shutting down plugin 'mysql_native_password'
2017-11-15T15:05:18.418176Z 0 [Note] Shutting down plugin 'binlog'
2017-11-15T15:05:18.418335Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

答案1

如你看到的:

2017-11-15T15:05:16.710592Z 0 [ERROR] unknown variable 'log_slow_queries=/var/log/mysql/mysql-slow.log'

系统变量之间存在差异slow_query_log_file慢查询日志

更正您的配置并阅读以下内容:https://stackoverflow.com/questions/36893799/mysql-5-7-log-slow-queries-error

相关内容