我曾尝试在 Linux Ubuntu 16.04 中打开 Mysql,但出现错误:
ilqar@ubuntu:~$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
然后我尝试启动 mysql 服务器:
ilqar@ubuntu:~$ sudo service mysql start
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
ilqar@ubuntu:~$ ^C
ilqar@ubuntu:~$ systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Sun 2018-01-21 10:39:04 +04; 17s ago
Process: 3620 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Control process exited, code=exited status=1
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Unit entered failed state.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jan 21 10:39:04 ubuntu systemd[1]: Stopped MySQL Community Server.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Start request repeated too quickly.
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
ilqar@ubuntu:~$ journalctl -xe
--
-- Unit mysql.service has finished shutting down.
Jan 21 10:39:04 ubuntu systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
Jan 21 10:39:04 ubuntu mysql-systemd-start[3611]: MySQL system database not found in /var/lib/mysql. Please run mysqld --initialize.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Control process exited, code=exited status=1
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Unit entered failed state.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jan 21 10:39:04 ubuntu systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Jan 21 10:39:04 ubuntu systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
Jan 21 10:39:04 ubuntu mysql-systemd-start[3620]: MySQL system database not found in /var/lib/mysql. Please run mysqld --initialize.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Control process exited, code=exited status=1
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Unit entered failed state.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jan 21 10:39:04 ubuntu systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Start request repeated too quickly.
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
我是 Linux 新手,请帮我找出问题所在。
答案1
我不得不删除 mysql 并重新安装它,现在它可以正常工作了
答案2
就我而言,mysql
由于此错误,服务未启动。
A mysqld process already exists
(从 找到的/var/log/mysql/error.log
)。
因此,我需要终止该进程并重新启动:
sudo killall mysqld mysqld_safe
ps aux | grep mysqld
sudo killall -9 mysqld mysqld_safe # use this if some mysqld process remained
和这对我有帮助。
答案3
相关错误信息是
MySQL system database not found in /var/lib/mysql. Please run mysqld --initialize.
尝试运行
sudo mysqld --initialize
然后尝试重新启动该服务。
答案4
当您删除 mysql 然后重新安装它时,问题就解决了。
要完全删除 mysql,请运行以下命令:
$ sudo apt-get remove --purge --auto-remove mysql-client-* mysql-common mysql-server-*
$ sudo rm -r /etc/mysql* /var/lib/mysql* /var/log/mysql*
要再次安装,请运行:
$ sudo apt-get install mysql-server