无法正确安装 mysql(无法启动?)

无法正确安装 mysql(无法启动?)

我在安装 mysql 时遇到问题,

sudo apt-get update
sudo apt-get install mysql-server

我也尝试过:

sudo dpkg -P mysql-server-5.1 mysql-server
sudo apt-get install mysql-server

我收到以下错误:

Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Mon 2017-05-15 14:43:06 CEST; 5ms ago
  Process: 22585 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 22584 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 22576 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 22584 (code=exited, status=1/FAILURE)
      CPU: 485ms

maj 15 14:43:06 XPS-13-9350 systemd[1]: mysql.service: Unit entered failed state.
maj 15 14:43:06 XPS-13-9350 systemd[1]: mysql.service: Failed with result 'exit-code'.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 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.
                                                                                                          Processing triggers for systemd (232-21ubuntu3) ...
Processing triggers for ureadahead (0.100.0-19) ...
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

如果我输入,mysql我会得到:

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

它似乎已经半安装好了,好像我mysql -u root -p收到了密码提示,但什么也没发生。

我尝试使用它来启动sudo service mysql start但它在 mysql.service 中收到此错误消息:

$ systemctl status mysql.service

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Mon 2017-05-15 14:24:24 CEST; 13s ago
  Process: 13333 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 13317 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 13333 (code=exited, status=1/FAILURE); Control PID: 13334 (mysql-systemd-s)
    Tasks: 2 (limit: 4915)
   Memory: 1.8M
      CPU: 353ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─13334 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─13397 sleep 1

maj 15 14:24:24 XPS-13-9350 systemd[1]: Starting MySQL Community Server...
maj 15 14:24:26 XPS-13-9350 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE

答案1

导致此问题的原因之一是您已经有一个 MySQL 实例正在运行。在我的例子中,我在安装这个新实例时有一个正在运行的 MySQL 的 Docker 镜像。

如果你已经安装了 Docker,请使用以下简单命令检查你正在运行的镜像ps

$ docker ps

如果您不确定实例是否在标准端口上运行 MySQL,您可以输入映像并登录到 MySQL 客户端,然后使用以下命令检查它在哪个端口上运行:

$ docker exec -it image_name bash
root@<container_id>/# mysql -u username -p
Enter password:
mysql > SHOW GLOBAL VARIABLES LIKE 'PORT';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+

或者你也可以直接停止图像:

$ docker stop image_name

还有其他方法可以同时运行多个 MySQL 实例,如果您没有 docker,我相信您可以执行一个ps -a | grep mysql来查看所有或至少最明显的 mysql 进程。

相关内容