无法让 MYSQL8 在 Ubuntu 20.04 上运行

无法让 MYSQL8 在 Ubuntu 20.04 上运行

我已经清除并重新安装了 mysql 客户端和服务器几次,我已经重新启动了系统,但我的计算机上的 mysql 仍然无法运行。

我根据另一篇 askubuntu 帖子运行了以下命令:

sudo apt-get --purge remove mysql-server mysql-common mysql-client.

sudo apt update && sudo apt dist-upgrade && sudo apt autoremove.

sudo apt-get install -y mysql-server mysql-client

然后我重新启动,什么也没发生。

命令输出:

mysql-V

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

sudo systemctl status mysql.service

Unit mysql.service could not be found.

sudo systemctl 启动 mysql.service

Failed to start mysql.service: Unit mysql.service not found.

sudo systemctl 启动 mysqld.service

Failed to start mysqld.service: Unit mysqld.service not found

我不知道从这里去哪里,因为我已经删除和清除了,而且 mysql 似乎安装好了只是不起作用。

mysql -h localhost -P 3306 -u root -p 或 mysql -h 127.0.0.1 -P 3306 -u root -p

相同的结果:

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

cat mysql.cnf                                                           1 ↵
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

任何帮助我都感激不尽。谢谢。

<------更新------> 刚刚运行了评论中推荐的命令,这是输出:

sudo apt-get install --reinstall mysql-server-8.0

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0 B/1,228 kB of archives.
After this operation, 0 B of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 326219 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.20-0ubuntu0.20.04.1_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: warning: old mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: error processing archive /var/cache/apt/archives/mysql-server-8.0_8.0.20-0ubuntu0.20.04.1_amd64.deb (--unpack):
 new mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
Failed to preset unit: File mysql.service: Link has been severed
/usr/bin/deb-systemd-helper: error: systemctl preset failed on mysql.service: No such file or directory
Failed to start mysql.service: Unit mysql.service not found.
invoke-rc.d: initscript mysql, action "start" failed.
Unit mysql.service could not be found.
dpkg: error while cleaning up:
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/mysql-server-8.0_8.0.20-0ubuntu0.20.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

ls -laF /lib/systemd/system/mysql.service

-rw-r--r-- 1 root root 524 Nov  6 11:34 /lib/systemd/system/mysql.service

出现此错误:: sudo apt-get install -f

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/1,228 kB of archives.
After this operation, 0 B of additional disk space will be used.
dpkg: error processing package mysql-server-8.0 (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Errors were encountered while processing:
 mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)

sudo dpkg--configure-a

dpkg: error processing package mysql-server-8.0 (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Errors were encountered while processing:
 mysql-server-8.0

答案1

尝试

sudo apt-get install --reinstall mysql-server-8.0

并检查 mysql.service 是否存在

ls -laF /lib/systemd/system/mysql.service

修复损坏的软件包

sudo apt-get install -f
sudo dpkg --configure -a

修复旧安装中可能遗留的 mysql.service

sudo killall mysqld
sudo systemctl disable mysql.service
sudo rm -rf /lib/systemd/system/mysql.service
sudo rm -rf /usr/lib/systemd/system/mysql.service
sudo rm -rf /etc/systemd/system/multi-user.target.wants/mysql.service
sudo rm -rf /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/mysql.service
sudo rm -rf /var/cache/apt/archives/mysql-server-*.deb

sudo apt-get install -f
sudo dpkg --configure -a

sudo apt-get install --reinstall mysql-server-8.0

答案2

关于这个特定的错误:

Unit mysql.service could not be found.

[我正在运行 Ubuntu 20.04]

我花了几个小时才发现这一点:几个月前我玩过 MariaDB 并卸载了它,但显然它没有完全/干净地卸载。它留下了两个符号链接

ls /etc/systemd/system
mysql.service -> /lib/systemd/system/mariadb.service
mysqld.service -> /lib/systemd/system/mariadb.service

链接文件被删除了,但链接本身没有被删除。我对两个链接都运行了“取消链接”,卸载了所有 mysql 包,然后dpkg -P重新安装,一切正常。

[我正在运行 Ubuntu 20.04]祝你好运。

答案3

当这种情况发生在我身上时,我需要做的就是运行:

sudo systemctl disable mysql.service

然后运行:

sudo systemctl enable mysql.service

这将删除旧的符号链接并创建新的符号链接。

答案4

我遇到了同样的问题,盲目地遵循了所有之前的说明,但无济于事。为了解决这个问题,我做了以下事情。

  1. 我将 /etc/mysql/FROZEN 重命名为 _FROZEN

     stephen@stephen-ubuntu:~$ sudo mv /etc/mysql/FROZEN _FROZEN
    
  2. 我运行了以下命令:

     stephen@stephen-ubuntu:~$ sudo apt-get install --reinstall mysql-server-8.0
     Reading package lists... Done
     Building dependency tree       
     Reading state information... Done    
     0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 81 not upgraded.    
     Need to get 0 B/1,249 kB of archives.
     After this operation, 0 B of additional disk space will be used.    
     Preconfiguring packages ...    
     (Reading database ... 262947 files and directories currently installed.)    
     Preparing to unpack .../mysql-server-8.0_8.0.21-0ubuntu0.20.04.4_amd64.deb ...    
     Downgrade from (at least) 10.3 to 5.7 is not possible.    
     MySQL has been frozen to prevent damage to your system. Please see /etc/mysql/FROZEN for help.    
     Unpacking mysql-server-8.0 (8.0.21-0ubuntu0.20.04.4) over (8.0.21-0ubuntu0.20.04.4) ...    
     Setting up mysql-server-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     MySQL has been frozen to prevent damage to your system. Please see /etc/mysql/FROZEN for help.    
     Processing triggers for systemd (245.4-4ubuntu3.2) ...    
    
  3. 由于其中一行说要降级到 5.7(包括新的 /etc/mysql/FROZEN 文件),并且我非常绝望,所以我尝试降级 MySQL。

     stephen@stephen-ubuntu:~$ sudo apt install mysql-server-5.7    
     Reading package lists... Done    
     Building dependency tree          
     Reading state information... Done    
     Package mysql-server-5.7 is not available, but is referred to by another package.    
     This may mean that the package is missing, has been obsoleted, or     
     is only available from another source    
     However the following packages replace it:    
       mariadb-server-10.3    
     E: Package 'mysql-server-5.7' has no installation candidate
    
  4. 我注意到“mysql-server-5.7”已被“mariadb-server-10.3”取代,所以我尝试了一下!

     stephen@stephen-ubuntu:~$ sudo apt install mariadb-server-10.3    
     Reading package lists... Done    
     Building dependency tree           
     Reading state information... Done    
     The following additional packages will be installed:    
       galera-3 libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libreadline5 libterm-readkey-perl mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common      
       mariadb-server-core-10.3 socat      
     Suggested packages:    
       libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl mailx mariadb-test tinyca      
     The following packages will be REMOVED:    
       mysql-client-8.0 mysql-client-core-8.0 mysql-server-8.0 mysql-server-core-8.0      
     The following NEW packages will be installed:    
       galera-3 libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libreadline5 libterm-readkey-perl mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common      
       mariadb-server-10.3 mariadb-server-core-10.3 socat      
     0 upgraded, 12 newly installed, 4 to remove and 81 not upgraded.    
     Need to get 19.3 MB of archives.    
     After this operation, 25.1 MB disk space will be freed.    
     Do you want to continue? [Y/n]     
     Get:1 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-common all 1:10.3.22-1ubuntu1 [15.6 kB]    
     Get:2 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 galera-3 amd64 25.3.29-1 [898 kB]    
     Get:3 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 libdbi-perl amd64 1.643-1 [730 kB]    
     Get:4 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 libconfig-inifiles-perl all 3.000002-1 [40.6 kB]    
     Get:5 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 libreadline5 amd64 5.2+dfsg-3build3 [100 kB]    
     Get:6 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-client-core-10.3 amd64 1:10.3.22-1ubuntu1 [5,805 kB]    
     Get:7 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-client-10.3 amd64 1:10.3.22-1ubuntu1 [1,125 kB]    
     Get:8 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-server-core-10.3 amd64 1:10.3.22-1ubuntu1 [6,011 kB]    
     Get:9 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 socat amd64 1.7.3.3-2 [323 kB]    
     Get:10 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 mariadb-server-10.3 amd64 1:10.3.22-1ubuntu1 [4,188 kB]    
     Get:11 http : //us.archive.ubuntu.com/ubuntu focal/universe amd64 libdbd-mysql-perl amd64 4.050-3 [82.8 kB]    
     Get:12 http : //us.archive.ubuntu.com/ubuntu focal/main amd64 libterm-readkey-perl amd64 2.38-1build1 [24.6 kB]    
     Fetched 19.3 MB in 1s (20.0 MB/s)                   
     Preconfiguring packages ...    
     (Reading database ... 262947 files and directories currently installed.)    
     Removing mysql-server-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     Removing mysql-client-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     Removing mysql-client-core-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     Removing mysql-server-core-8.0 (8.0.21-0ubuntu0.20.04.4) ...    
     Selecting previously unselected package mariadb-common.    
     (Reading database ... 262740 files and directories currently installed.)    
     Preparing to unpack .../0-mariadb-common_1%3a10.3.22-1ubuntu1_all.deb ...    
     Unpacking mariadb-common (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package galera-3.    
     Preparing to unpack .../1-galera-3_25.3.29-1_amd64.deb ...    
     Unpacking galera-3 (25.3.29-1) ...    
     Selecting previously unselected package libdbi-perl:amd64.    
     Preparing to unpack .../2-libdbi-perl_1.643-1_amd64.deb ...    
     Unpacking libdbi-perl:amd64 (1.643-1) ...    
     Selecting previously unselected package libconfig-inifiles-perl.    
     Preparing to unpack .../3-libconfig-inifiles-perl_3.000002-1_all.deb ...    
     Unpacking libconfig-inifiles-perl (3.000002-1) ...    
     Selecting previously unselected package libreadline5:amd64.    
     Preparing to unpack .../4-libreadline5_5.2+dfsg-3build3_amd64.deb ...    
     Unpacking libreadline5:amd64 (5.2+dfsg-3build3) ...    
     Selecting previously unselected package mariadb-client-core-10.3.    
     Preparing to unpack .../5-mariadb-client-core-10.3_1%3a10.3.22-1ubuntu1_amd64.deb ...    
     Unpacking mariadb-client-core-10.3 (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package mariadb-client-10.3.    
     Preparing to unpack .../6-mariadb-client-10.3_1%3a10.3.22-1ubuntu1_amd64.deb ...    
     Unpacking mariadb-client-10.3 (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package mariadb-server-core-10.3.    
     Preparing to unpack .../7-mariadb-server-core-10.3_1%3a10.3.22-1ubuntu1_amd64.deb ...    
     Unpacking mariadb-server-core-10.3 (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package socat.    
     Preparing to unpack .../8-socat_1.7.3.3-2_amd64.deb ...
     Unpacking socat (1.7.3.3-2) ...    
     Setting up mariadb-common (1:10.3.22-1ubuntu1) ...    
     update-alternatives: using /etc/mysql/mariadb.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode    
     Selecting previously unselected package mariadb-server-10.3.    
     (Reading database ... 263114 files and directories currently installed.)    
     Preparing to unpack .../mariadb-server-10.3_1%3a10.3.22-1ubuntu1_amd64.deb ...    
     /var/lib/mysql: found previous version 10.3    
     Unpacking mariadb-server-10.3 (1:10.3.22-1ubuntu1) ...    
     Selecting previously unselected package libdbd-mysql-perl:amd64.    
     Preparing to unpack .../libdbd-mysql-perl_4.050-3_amd64.deb ...    
     Unpacking libdbd-mysql-perl:amd64 (4.050-3) ...    
     Selecting previously unselected package libterm-readkey-perl.    
     Preparing to unpack .../libterm-readkey-perl_2.38-1build1_amd64.deb ...    
     Unpacking libterm-readkey-perl (2.38-1build1) ... 
     Setting up libconfig-inifiles-perl (3.000002-1) ...    
     Setting up libreadline5:amd64 (5.2+dfsg-3build3) ...    
     Setting up socat (1.7.3.3-2) ...    
     Setting up mariadb-server-core-10.3 (1:10.3.22-1ubuntu1) ...    
     Setting up galera-3 (25.3.29-1) ...    
     Setting up mariadb-client-core-10.3 (1:10.3.22-1ubuntu1) ...    
     Setting up libterm-readkey-perl (2.38-1build1) ...    
     Setting up libdbi-perl:amd64 (1.643-1) ...    
     Setting up mariadb-client-10.3 (1:10.3.22-1ubuntu1) ...    
     Setting up libdbd-mysql-perl:amd64 (4.050-3) ...    
     Setting up mariadb-server-10.3 (1:10.3.22-1ubuntu1) ...    
     Installing new version of config file /etc/apparmor.d/usr.sbin.mysqld ...    
     Installing new version of config file /etc/init.d/mysql ...    
     Installing new version of config file /etc/logrotate.d/mysql-server ...    
     Installing new version of config file /etc/mysql/debian-start ...    
     mariadb.service is a disabled or a static unit, not starting it.    
     Processing triggers for libc-bin (2.31-0ubuntu9) ...    
     Processing triggers for systemd (245.4-4ubuntu3.2) ...    
     Processing triggers for man-db (2.9.1-1) ...
     Processing triggers for menu (2.1.47ubuntu4) ...
    

随后我去 Synaptic 检查损坏的软件包,发现“mysql-server-8.0”不再存在或安装。

相关内容