完全停留在安装/服务停止 MYSQL

完全停留在安装/服务停止 MYSQL

最近,我进入了 Linux 服务器的世界(我自己的小型功能强大的 NAS,呵呵),我试图为我的 wordpress 网站安装 mysql。安装时,发生了以下情况:

Errors were encountered while processing: /tmp/apt-dpkg-install-0TJWYH/06-mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

然后一切就开始走下坡路了。

Preparing to unpack .../mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
invoke-rc.d returned 5
There is a MySQL server running, but we failed in our attempts to stop it.
Stop it yourself and try again!
dpkg: error processing archive /var/cache/apt/archives/mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb (--unpack):
new mysql-server-8.0 package pre-installation script subprocess returned error exit status 1
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_8.0.23-0ubuntu0.20.04.1_all.deb ...
Unpacking mysql-server (8.0.23-0ubuntu0.20.04.1) ...
Errors were encountered while processing:
/var/cache/apt/archives/mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

root@vicsserver:/home/victoroos# sudo mysql_secure_installation
mysql_secure_installation: [ERROR] unknown variable 'default-character-set=utf8mb4'.

Securing the MySQL server deployment.

Enter password for user root:
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

root@vicsserver:/home/victoroos# sudo service mysql start
Failed to start mysql.service: Unit mysql.service not found.

我已经尝试过以下步骤:

停止或启动:

Stopping mysql (via systemctl): mysql.serviceFailed to stop mysql.service: Unit mysql.service not loaded.
failed!

当我开始时:

Starting mysql (via systemctl): mysql.serviceFailed to start mysql.service: Unit mysql.service not found.
failed!

安装:

victoroos@vicsserver:~$ sudo apt -f install
[sudo] password for victoroos:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libmysqlclient21 libsnappy1v5 libterm-readkey-perl mariadb-common php7.4-mysql
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
mysql-server-8.0
Suggested packages:
mailx tinyca
The following NEW packages will be installed:
mysql-server-8.0
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/1275 kB of archives.
After this operation, 1481 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
(Reading database ... 131672 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
invoke-rc.d returned 5
There is a MySQL server running, but we failed in our attempts to stop it.
Stop it yourself and try again!
dpkg: error processing archive /var/cache/apt/archives/mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb (--unpack):
new mysql-server-8.0 package pre-installation script subprocess returned error exit status 1
Errors were encountered while processing:
/var/cache/apt/archives/mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
so quite a loop dy loop.

Thank for helping me out though, I'm really stuck

And when trying to stop it differently, I get:

victoroos@vicsserver:~$ service mysqld stop
Failed to stop mysqld.service: Interactive authentication required.
See system logs and 'systemctl status mysqld.service' for details.

victoroos@vicsserver:~$ su root
Password:
root@vicsserver:/home/victoroos# service mysqld stop
Failed to stop mysqld.service: Unit mysqld.service not loaded.
root@vicsserver:/home/victoroos#

victoroos@vicsserver:~$ sudo apt-get purge mysql-common mysql-server-8.0
[sudo] password for victoroos:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'mysql-server-8.0' is not installed, so not removed
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
libmysqlclient21 : Depends: mysql-common (>= 5.5) but it is not going to be installed
mariadb-common : Depends: mysql-common (>= 5.6.25) but it is not going to be installed
mysql-client-8.0 : Depends: mysql-common (>= 5.5) but it is not going to be installed
mysql-server : Depends: mysql-server-8.0 but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
victoroos@vicsserver:~$ ^C
victoroos@vicsserver:~$ sudo apt --fix-broken
E: Command line option --fix-broken is not understood in combination with the other options
victoroos@vicsserver:~$ sudo apt-get purge mysql-common mysql-server*
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'mysql-server-5.5' for glob 'mysql-server*'
Note, selecting 'mysql-server-5.6' for glob 'mysql-server*'
Note, selecting 'mysql-server-5.7' for glob 'mysql-server*'
Note, selecting 'mysql-server' for glob 'mysql-server*'
Note, selecting 'mysql-server-8.0' for glob 'mysql-server*'
Note, selecting 'mysql-server-core-5.5' for glob 'mysql-server*'
Note, selecting 'mysql-server-core-5.6' for glob 'mysql-server*'
Note, selecting 'mysql-server-core-5.7' for glob 'mysql-server*'
Note, selecting 'mysql-server-core-8.0' for glob 'mysql-server*'
Package 'mysql-server-5.5' is not installed, so not removed
Package 'mysql-server-5.7' is not installed, so not removed
Package 'mysql-server-core-5.7' is not installed, so not removed
Package 'mysql-server-core-5.5' is not installed, so not removed
Package 'mysql-server-core-5.6' is not installed, so not removed
Package 'mysql-server-5.6' is not installed, so not removed
Package 'mysql-server-8.0' is not installed, so not removed
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
libmysqlclient21 : Depends: mysql-common (>= 5.5) but it is not going to be installed
mariadb-common : Depends: mysql-common (>= 5.6.25) but it is not going to be installed
mysql-client-8.0 : Depends: mysql-common (>= 5.5) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
victoroos@vicsserver:~$ sudo apt-get purge mysql-common mysql-common*
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'mysql-common-5.6' for glob 'mysql-common*'
Note, selecting 'mysql-common' for glob 'mysql-common*'
Note, selecting 'mysql-common' instead of 'mysql-common-5.6'
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
libmysqlclient21 : Depends: mysql-common (>= 5.5) but it is not going to be installed
mariadb-common : Depends: mysql-common (>= 5.6.25) but it is not going to be installed
mysql-client-8.0 : Depends: mysql-common (>= 5.5) but it is not going to be installed
mysql-server : Depends: mysql-server-8.0 but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

当然,我尝试修复损坏的问题,因为它打印得很好:)

root@vicsserver:/home/victoroos# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libmysqlclient21 libsnappy1v5 libterm-readkey-perl mariadb-common php7.4-mysql
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  mysql-server-8.0
Suggested packages:
  mailx tinyca
The following NEW packages will be installed:
  mysql-server-8.0
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
1 not fully installed or removed.
Need to get 0 B/1275 kB of archives.
After this operation, 1481 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
(Reading database ... 131672 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
invoke-rc.d returned 5
There is a MySQL server running, but we failed in our attempts to stop it.
Stop it yourself and try again!
dpkg: error processing archive /var/cache/apt/archives/mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb (--unpack):
 new mysql-server-8.0 package pre-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/mysql-server-8.0_8.0.23-0ubuntu0.20.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@vicsserver:/home/victoroos#

结论很简短,我需要能够停止显然正在运行的服务。但我不能。为什么?我应该采取什么步骤?我希望我已经给你足够的信息来帮助我解决问题。

擦洗后:

victoroos@vicsserver:~$ sudo apt purge mysql-server mysql-client \
>                  mysql-common mysql-server-core-* mysql-client-core-*
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'mysql-server-core-5.5' for glob 'mysql-server-core-*'
Note, selecting 'mysql-server-core-5.6' for glob 'mysql-server-core-*'
Note, selecting 'mysql-server-core-5.7' for glob 'mysql-server-core-*'
Note, selecting 'mysql-server-core-8.0' for glob 'mysql-server-core-*'
Package 'mysql-server-core-5.7' is not installed, so not removed
Package 'mysql-server-core-5.5' is not installed, so not removed
Package 'mysql-server-core-5.6' is not installed, so not removed
Note, selecting 'mysql-client-core-5.5' for glob 'mysql-client-core-*'
Note, selecting 'mysql-client-core-5.6' for glob 'mysql-client-core-*'
Note, selecting 'mysql-client-core-5.7' for glob 'mysql-client-core-*'
Note, selecting 'mysql-client-core-8.0' for glob 'mysql-client-core-*'
Package 'mysql-client-core-5.7' is not installed, so not removed
Package 'mysql-client-core-5.5' is not installed, so not removed
Package 'mysql-client-core-5.6' is not installed, so not removed
Package 'mysql-client' is not installed, so not removed
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 libmysqlclient21 : Depends: mysql-common (>= 5.5) but it is not going to be installed
 mariadb-common : Depends: mysql-common (>= 5.6.25) but it is not going to be installed
 mysql-client-8.0 : Depends: mysql-client-core-8.0 but it is not going to be installed
                    Depends: mysql-common (>= 5.5) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

答案1

以下步骤通常用于解决“最坏情况”,即正在运行的进程无法识别所有者,您只需停止它即可。如果这是您自己在机器上安装的新 Ubuntu Server 20.04 安装,那么某物您安装的服务器上还安装了 MySQL(或 MariaDB)。在过于疯狂并终止进程之前,让我们确认一下您的服务器上安装的 MySQL 版本:

$ mysql -V

如果您看到类似下一行的内容,那么也许您根本不需要安装 MySQL:

mysql  Ver 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

弄清楚安装来自哪里,连接sudo(例如sudo mysql),并为 WordPress 准备好数据库。

否则...我们就烧焦一些土地吧。


重要的

下面的一组指令将完成几件事:

  1. 终止当前正在运行且不响应标准stop命令的MySQL 进程
  2. 删除当前安装的 MySQL 版本
  3. 安装 MySQL 服务器的 Canonical 版本

有了免责声明,让我们开始寻找 MySQL:

  1. 使用top(或任何其他进程查看工具)来识别PIDMySQL:

    $ sudo top -p `pgrep mysql | tr "\\n" "," | sed 's/,$//'`
    

    笔记:你可以简单地使用 sudo top但是上面的命令将限制输出仅到 MySQL,从而节省时间。

    你应该得到类似这样的结果:

    top - 23:31:12 up 10 days, 22:02,  2 users,  load average: 0.01, 0.04, 0.00
    Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
    %Cpu(s):  0.3 us,  0.3 sy,  0.0 ni, 99.2 id,  0.1 wa,  0.0 hi,  0.1 si,  0.0 st
    MiB Mem :   7725.7 total,    141.2 free,   3083.2 used,   4501.3 buff/cache
    MiB Swap:  31250.0 total,  31026.2 free,    223.8 used.   3577.0 avail Mem 
    
        PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
     112265 mysql     20   0 3979708 693688  13032 S   0.3   8.8  50:35.45 mysqld
    
  2. (出于很多原因,这很糟糕,但是……)终止进程。如果您从 内部执行此操作top,请按K,然后按PID数字。如果您选择从命令行终止进程,您可以这样做:

    $ sudo kill -9 112265
    

    笔记:一定要改变 112265 为您在 MySQL 中看到的任何值。

  3. 检查您的系统上当前安装了哪些 MySQL 包:

    $ sudo apt list "mysql*" --installed
    

    您可能会看到类似这样的内容,但版本号不同:

    Listing... Done
    mysql-client-8.0/focal-security,now 8.0.23-0ubuntu0.20.04.1 amd64 [installed,automatic]
    mysql-client-core-8.0/focal-security,now 8.0.23-0ubuntu0.20.04.1 amd64 [installed,automatic]
    mysql-client/focal-security,focal-security,now 8.0.23-0ubuntu0.20.04.1 all [installed]
    mysql-common/focal,focal,now 5.8+1.0.5ubuntu2 all [installed,automatic]
    mysql-server-8.0/focal-security,now 8.0.23-0ubuntu0.20.04.1 amd64 [installed,automatic]
    mysql-server-core-8.0/focal-security,now 8.0.23-0ubuntu0.20.04.1 amd64 [installed,automatic]
    mysql-server/focal-security,focal-security,now 8.0.23-0ubuntu0.20.04.1 all [installed]
    
  4. 从系统中清除 MySQL:

    $ sudo apt purge mysql-server mysql-client \
                     mysql-common "mysql-server-core-*" "mysql-client-core-*"
    

    笔记:您将获得一长串要删除的软件包。查看这些软件包。确保您了解哪些软件包将从系统中被删除。如果您愿意删除它们,请同意提示并让 apt 做它的事情。

  5. 确保apt干净且最新:

    $ sudo apt autoremove
    $ sudo apt autoclean
    $ sudo apt update
    
  6. 重新安装 MySQL 服务器:

    $ sudo apt install mysql-server
    
  7. 运行安全安装程序并设置好的root密码:

    $ sudo mysql_secure_installation
    
  8. 完成后,连接到 MySQL 并确保一切正常:

    $ sudo mysql
    

    如果您可以登录,则表明服务器正在运行。您还可以查看现有数据库(如果这是第一次安装 MySQL,则应仅限于系统数据库)。

    mysql> SHOW DATABASES;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)
    
  9. 创建一个管理员帐户,因为您不能让 WordPress(或任何其他工具)以以下方式连接到 MySQL root

    CREATE USER 'victoroos'@'localhost' IDENTIFIED WITH mysql_native_password BY 'SuperSecretPassword!123';
    

    同时授予该帐户所有权限,以便本质上一个root帐户:

    GRANT ALL ON *.* TO 'victoroos'@'localhost' WITH GRANT OPTION;
    
  10. 如果还没有安装 WordPress ... 或 Apache 和 PHP,请安装。

相关内容