web-dev-qa-db-ja.com

MySQL Ubuntu 16.04が起動しない

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の初心者です。問題を見つけるのを手伝ってください。

2
Ilqar Rasulov

Mysqlを削除して再インストールする必要がありましたが、今では動作します

2
Ilqar Rasulov

関連するエラーメッセージは

MySQL system database not found in /var/lib/mysql. Please run mysqld --initialize.

実行してみてください

Sudo mysqld --initialize

その後、サービスを再度開始してください。

0
Chai T. Rex

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
0
user760819