AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1235829
Accepted
CodeConnoisseur
CodeConnoisseur
Asked: 2020-05-06 12:06:29 +0800 CST2020-05-06 12:06:29 +0800 CST 2020-05-06 12:06:29 +0800 CST

无法让 MYSQL8 在 Ubuntu 20.04 上运行

  • 772

我已经清除并重新安装了 mysql-client 和服务器几次,我重新启动了我的系统,但我无法让 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 start 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
server mysql 20.04
  • 4 4 个回答
  • 41850 Views

4 个回答

  • Voted
  1. Best Answer
    ExploitFate
    2020-05-06T12:12:39+08:002020-05-06T12:12:39+08:00

    尝试

    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
    
    
    • 18
  2. Dean
    2020-11-29T15:17:07+08:002020-11-29T15:17:07+08:00

    关于这个特定的错误:

    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
    

    链接文件已被链接本身删除。我在两个链接上都运行了“unlink”,卸载了所有 mysql 软件包dpkg -P并重新安装,结果很好。

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

    • 6
  3. jrvision
    2021-10-29T06:37:40+08:002021-10-29T06:37:40+08:00

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

    sudo systemctl disable mysql.service
    

    然后运行:

    sudo systemctl enable mysql.service
    

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

    • 2
  4. Stephen Dittoe
    2020-08-21T19:40:23+08:002020-08-21T19:40:23+08:00

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

    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”不再存在,也不再安装。

    • 1

相关问题

  • 如何将 MySQL 数据文件移动到不同的分区?

  • 如何从命令行刻录双层 dvd iso

  • 如果在服务器机器上运行 Ubuntu 桌面版,性能损失是多少?

  • 将桌面版剥离为服务器版的最简单方法是什么?

  • 如何与无头服务器进行图形交互?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve