无法安装或启动 MySQL

无法安装或启动 MySQL

我正在尝试将我的一个项目从另一个 VPS 移过来,但我认为我的 SQL 数据库已经乱了套。我确信问题已经出现,因为我的 VPS 上有多个 MySQL 实例,但是我无法删除所有文件。

因此首先我尝试登录 MySQL。

root@fileserver:~# mysql --user=root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

由于我的数据库中没有太多重要信息,我决定通过执行以下操作来删除 MySQL

root@fileserver:~# sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libaio1 libevent-core-2.0-5 libnuma1 mysql-client-core-5.7 mysql-server-core-5.7
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  mysql-client* mysql-client-5.7* mysql-common* mysql-server* mysql-server-5.7*
0 upgraded, 0 newly installed, 5 to remove and 18 not upgraded.
2 not fully installed or removed.
After this operation, 82.7 MB disk space will be freed.
(Reading database ... 150440 files and directories currently installed.)
Removing mysql-server (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
update-alternatives: warning: alternative /etc/mysql/my.cnf.fallback (part of link group my.cnf) doesn't exist; removing from list of alternatives
update-alternatives: warning: alternative /etc/mysql/mysql.cnf (part of link group my.cnf) doesn't exist; removing from list of alternatives
update-alternatives: warning: /etc/alternatives/my.cnf is dangling; it will be updated with best choice
Purging configuration files for mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-client (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-client-5.7 (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-common (5.7.23-0ubuntu0.16.04.1) ...
Purging configuration files for mysql-common (5.7.23-0ubuntu0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu21.4) ...
root@fileserver:~# sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'mysql-client' is not installed, so not removed
Package 'mysql-common' is not installed, so not removed
Package 'mysql-server' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  libaio1 libevent-core-2.0-5 libnuma1 mysql-client-core-5.7 mysql-server-core-5.7
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 18 not upgraded.
root@fileserver:~# sudo apt-get autoremove -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  libaio1 libevent-core-2.0-5 libnuma1 mysql-client-core-5.7 mysql-server-core-5.7
0 upgraded, 0 newly installed, 5 to remove and 18 not upgraded.
After this operation, 78.0 MB disk space will be freed.
(Reading database ... 150299 files and directories currently installed.)
Removing mysql-server-core-5.7 (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-client-core-5.7 (5.7.23-0ubuntu0.16.04.1) ...
Removing libaio1:amd64 (0.3.110-2) ...
Removing libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
Removing libnuma1:amd64 (2.0.11-1ubuntu1.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
root@fileserver:~# sudo apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done
root@fileserver:~# rm -rf /etc/mysql
root@fileserver:~# sudo find / -iname 'mysql*' -exec rm -rf {} \;
find: '/var/lib/mysql-files': No such file or directory
find: '/var/lib/mysql-keyring': No such file or directory
root@fileserver:~#

所以我不确定这是否有效,因为有相当多的错误,我试图重新安装 MySQL(这就是为什么我认为我已经把它弄坏了)

root@fileserver:~# sudo apt-get install mysql-client mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  mysql-client mysql-server
0 upgraded, 2 newly installed, 0 to remove and 18 not upgraded.
1 not fully installed or removed.
Need to get 0 B/20.9 kB of archives.
After this operation, 219 kB of additional disk space will be used.
Selecting previously unselected package mysql-client.
(Reading database ... 150436 files and directories currently installed.)
Preparing to unpack .../mysql-client_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-client (5.7.23-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-server (5.7.23-0ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 2
Setting up mysql-client (5.7.23-0ubuntu0.16.04.1) ...
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

此后我尝试启动 MySQL

root@fileserver:~# sudo /etc/init.d/mysql start
[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
     failed!

因此我按照建议查看了 journalctl -xe,这是显示的日志

root@fileserver:~# journalctl -xe
-- The process /usr/share/mysql/mysql-systemd-start could not be executed and failed.
--
-- The error number returned by this process is 3.
Sep 30 06:35:38 fileserver systemd[1]: mysql.service: Control process exited, code=exited status=217
Sep 30 06:35:38 fileserver 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.
Sep 30 06:35:38 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:35:38 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:35:39 fileserver 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.
Sep 30 06:35:39 fileserver 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.
Sep 30 06:35:39 fileserver systemd[16248]: mysql.service: Failed at step USER spawning /usr/share/mysql/mysql-systemd-start: No such process
-- Subject: Process /usr/share/mysql/mysql-systemd-start could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /usr/share/mysql/mysql-systemd-start could not be executed and failed.
--
-- The error number returned by this process is 3.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Control process exited, code=exited status=217
Sep 30 06:35:39 fileserver 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.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:35:39 fileserver 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.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Start request repeated too quickly.
Sep 30 06:35:39 fileserver 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.

root@fileserver:~# mysql --user=root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@fileserver:~# sudo apt-get install mysql-client mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  mysql-client mysql-server
0 upgraded, 2 newly installed, 0 to remove and 18 not upgraded.
1 not fully installed or removed.
Need to get 0 B/20.9 kB of archives.
After this operation, 219 kB of additional disk space will be used.
Selecting previously unselected package mysql-client.
(Reading database ... 150436 files and directories currently installed.)
Preparing to unpack .../mysql-client_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-client (5.7.23-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-server (5.7.23-0ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 2
Setting up mysql-client (5.7.23-0ubuntu0.16.04.1) ...
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@fileserver:~# ^C
root@fileserver:~# ^C
root@fileserver:~# 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.
root@fileserver:~# sudo /etc/init.d/mysql start
[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
 failed!
root@fileserver:~# ^C
root@fileserver:~# 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-09-30 06:38:37 EDT; 25s ago
  Process: 16482 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=217/USER)
 Main PID: 15680 (code=exited, status=203/EXEC)

Sep 30 06:38:37 fileserver systemd[1]: Failed to start MySQL Community Server.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:38:37 fileserver systemd[1]: Stopped MySQL Community Server.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Start request repeated too quickly.
Sep 30 06:38:37 fileserver systemd[1]: Failed to start MySQL Community Server.
root@fileserver:~# ^C
root@fileserver:~# journalctl -xe
-- The process /usr/share/mysql/mysql-systemd-start could not be executed and failed.
--
-- The error number returned by this process is 3.
Sep 30 06:38:36 fileserver systemd[1]: mysql.service: Control process exited, code=exited status=217
Sep 30 06:38:36 fileserver 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.
Sep 30 06:38:36 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:38:36 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:38:37 fileserver 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.
Sep 30 06:38:37 fileserver 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.
Sep 30 06:38:37 fileserver systemd[16482]: mysql.service: Failed at step USER spawning /usr/share/mysql/mysql-systemd-start: No such process
-- Subject: Process /usr/share/mysql/mysql-systemd-start could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /usr/share/mysql/mysql-systemd-start could not be executed and failed.
--
-- The error number returned by this process is 3.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Control process exited, code=exited status=217
Sep 30 06:38:37 fileserver 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.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:38:37 fileserver 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.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Start request repeated too quickly.
Sep 30 06:38:37 fileserver 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.

奇怪的是,即使在我完全卸载 MySQL 之后,我仍然可以尝试使用 mysql --user=root -p 登录,并且可以输入我的密码并出现错误 2002。如果我完全卸载它,这肯定不会发生吧?

任何帮助都将不胜感激,我在这方面还只是个初学者,并不完全理解日志的所有输出。

希望我发布的信息足够了。干杯。

答案1

如果我已经完全卸载它,这肯定不会发生吧?

显然你还没有完全卸载它。mysql 有两个部分,客户端和服务器。它们通常通过不同的包安装。命令 mysql 是客户端程序。它运行并请求你告诉它请求的信息。然后它尝试使用默认参数连接到本地服务器。本地服务器没有运行,所以你得到一个 2002 错误...无法连接到服务器...

答案2

所以我不太了解 Ubuntu,但是你的错误是这样的......

Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-server (5.7.23-0ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
**update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist**
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 2

您可以尝试将默认的 mysql.cnf 文件复制到该位置作为快速修复,但您一定要尝试找出该错误是什么/它来自哪里......

相关内容