收到错误 2002 后无法重新启动 mysql 服务无法连接到本地 mysql 服务器

收到错误 2002 后无法重新启动 mysql 服务无法连接到本地 mysql 服务器

从昨天开始,我在连接到 mysql 时出现此错误:

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

我已经有大约 1 个月没有动过我的设置了,所以我不认为这是由我试图对设置进行的任何更改引起的。当我尝试使用以下命令重新启动 mysql 服务时

service mysqld restart

我收到此错误:

Stopping mysqld:                                           [  OK  ]
touch: cannot touch ‘/var/log/mysqld.log’: Permission denied
chown: changing ownership of ‘/var/log/mysqld.log’: Operation not permitted
chmod: changing permissions of ‘/var/log/mysqld.log’: Operation not permitted
chown: changing ownership of ‘/var/lib/mysql’: Operation not permitted
chmod: changing permissions of ‘/var/lib/mysql’: Operation not permitted
MySQL Daemon failed to start.

如果我尝试:

sudo service mysqld restart

我刚刚得到:

Stopping mysqld:                                           [  OK  ]
MySQL Daemon failed to start.
Starting mysqld:                                           [FAILED]

根据我在其他服务器故障线程上读到的有关相同错误的内容,我认为这是一个权限问题,但我仍然感到困惑,因为我应该有权执行该目录中的文件:

drwxr-xr-x 6 mysql mysql 4096 Jun 21 16:42 /var/lib/mysql

更新:日志如下。看起来像是内存问题,但我不知道如何解决:

140618 20:17:46 mysqld_safe Number of processes running now: 0
140618 20:17:46 mysqld_safe mysqld restarted
140618 20:17:47 [Note] Plugin 'FEDERATED' is disabled.
140618 20:17:47 InnoDB: The InnoDB memory heap is disabled
140618 20:17:47 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140618 20:17:47 InnoDB: Compressed tables use zlib 1.2.7
140618 20:17:47 InnoDB: Using Linux native AIO
140618 20:17:47 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
140618 20:17:47 InnoDB: Completed initialization of buffer pool
140618 20:17:47 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140618 20:17:47 [ERROR] Plugin 'InnoDB' init function returned error.
140618 20:17:47 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140618 20:17:47 [ERROR] Unknown/unsupported storage engine: InnoDB
140618 20:17:47 [ERROR] Aborting

140618 20:17:47 [Note] /usr/libexec/mysqld: Shutdown complete

140618 20:17:47 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
140621 16:42:49 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140621 16:42:49 [Note] Plugin 'FEDERATED' is disabled.
140621 16:42:49 InnoDB: The InnoDB memory heap is disabled
140621 16:42:49 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140621 16:42:49 InnoDB: Compressed tables use zlib 1.2.7
140621 16:42:49 InnoDB: Using Linux native AIO
140621 16:42:50 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
140621 16:42:50 InnoDB: Completed initialization of buffer pool
140621 16:42:50 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140621 16:42:50 [ERROR] Plugin 'InnoDB' init function returned error.
140621 16:42:50 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140621 16:42:50 [ERROR] Unknown/unsupported storage engine: InnoDB
140621 16:42:50 [ERROR] Aborting

140621 16:42:50 [Note] /usr/libexec/mysqld: Shutdown complete

140621 16:42:50 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

更新:在这里找到了答案,即设置交换文件。我遵循的有关如何执行此操作的完整详细信息可在此处找到:http://www.prowebdev.us/2012/05/amazon-ec2-linux-micro-swap-space.html

答案1

您需要确保所有 mysql 文件都归 mysql 用户所有。验证 mysql 日志文件是否归 MySQL 用户所有。

ls -l /var/log/mysql*

如果没有设置正确的所有者:

chown mysql:mysql /var/log/mysql....

对 my.cnf 中列出的所有目录执行相同操作:

root# grep mysql /etc/mysql/my.cnf
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /data/mysql
log_bin=/data/mysql/binlogs/mysql-bin.log
slow_query_log_file=/var/log/mysql_slow_query.log
log-error=/var/log/mysql_error.log
innodb_data_home_dir = /data/mysql

对于目录使用递归 chown:

chown mysql:mysql -R /data/mysql

相关内容