我正在运行 ubuntu 服务器。当我尝试登录 mysql(正在运行)时,出现以下错误
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
但是文件夹中不存在mysqld.sock文件/var/run/mysqld
。执行ps aux | grep mysql
命令时,我意识到mysql服务器没有运行。
然后我尝试使用重新启动 mysql 服务器
service mysql start
service mysql restart
/etc/init.d/mysql start
但是,在这三种情况下,启动过程都失败了。
/var/log/mysql/mysql.log
并且/var/log/mysql/mysql.err
文件是空的。
但/var/log/error.log
显示以下信息:
140425 12:49:05 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
140425 12:49:05 [Note] Plugin 'FEDERATED' is disabled.
140425 12:49:05 InnoDB: The InnoDB memory heap is disabled
140425 12:49:05 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140425 12:49:05 InnoDB: Compressed tables use zlib 1.2.8
140425 12:49:05 InnoDB: Using Linux native AIO
140425 12:49:05 InnoDB: Initializing buffer pool, size = 3.0G
140425 12:49:05 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 26214400 bytes!
140425 12:49:05 [ERROR] Plugin 'InnoDB' init function returned error.
140425 12:49:05 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140425 12:49:05 [ERROR] /usr/sbin/mysqld: unknown variable 'record_buffer=64M'
140425 12:49:05 [ERROR] Aborting
140425 12:49:05 [Note] /usr/sbin/mysqld: Shutdown complete
答案1
答案2
这解决了我的问题:
mkdir /var/run/mysqld
touch /var/run/mysqld/mysqld.sock
chown -R mysql /var/run/mysqld
/etc/init.d/mysql restart
答案3
我按照以下方式解决了该问题:
chown -R mysql:mysql /var/lib/mysql
mysql_install_db --user=mysql -ldata=/var/lib/mysql/
在另一个情况下,我遇到这种情况是因为mysql 守护进程无法启动。因此请使用命令 - 启动守护进程,mysqld start
然后尝试启动服务。
答案4
通过添加新的交换空间来增加可用 RAM 也可能有帮助。步骤如下这里
确保创建的 /swapfile 的大小小于显示的可用空间
df -h
例如对我来说 df- h 的输出是:
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 1.2G 6.3G 16% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 492M 12K 492M 1% /dev
tmpfs 100M 336K 99M 1% /run
所以我用2G创建
sudo fallocate -l 2G /swapfile
然后启动服务
sudo /etc/init.d/mysql restart
希望这能有所帮助。祝一切顺利。