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 / 问题 / 1531272
Accepted
mstdmstd
mstdmstd
Asked: 2024-10-27 15:57:20 +0800 CST2024-10-27 15:57:20 +0800 CST 2024-10-27 15:57:20 +0800 CST

有时我会收到错误“未找到 MySQL 配置”。如何修复?

  • 772

有一段时间我的 MySQL 服务器停止工作了(几个月前我在家里安装了 kubuntu 22.04)

我检查命令:

# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@master-at-home:/path# mysql -h 127.0.0.1 -P 3306 -u root
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
root@master-at-home:/path# sudo service mysql start
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.
root@master-at-home:/path# systemctl status mysql.service
× mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2024-10-27 09:33:42 EET; 10s ago
Process: 32412 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
CPU: 2ms

master-at-home systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
master-at-home systemd[1]: Stopped MySQL Community Server.
master-at-home systemd[1]: mysql.service: Start request repeated too quickly.
master-at-home systemd[1]: mysql.service: Failed with result 'exit-code'.
master-at-home systemd[1]: Failed to start MySQL Community Server.
root@master-at-home:/path# journalctl -xeu mysql.service
░░ The job identifier is 3931 and the job result is done.
master-at-home systemd[1]: Starting MySQL Community Server...
░░ Subject: A start job for unit mysql.service has begun execution
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit mysql.service has begun execution.
░░
░░ The job identifier is 3931.
master-at-home mysql-systemd-start[32412]: MySQL configuration not found at /etc/mysql/my.cnf. Please create one.
master-at-home systemd[1]: mysql.service: Control process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ An ExecStartPre= process belonging to unit mysql.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
master-at-home systemd[1]: mysql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit mysql.service has entered the 'failed' state with result 'exit-code'.
master-at-home systemd[1]: Failed to start MySQL Community Server.
░░ Subject: A start job for unit mysql.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit mysql.service has finished with a failure.
░░
░░ The job identifier is 3931 and the job result is failed.
master-at-home systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ Automatic restarting of the unit mysql.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
master-at-home systemd[1]: Stopped MySQL Community Server.
░░ Subject: A stop job for unit mysql.service has finished
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A stop job for unit mysql.service has finished.
░░
░░ The job identifier is 4065 and the job result is done.
master-at-home systemd[1]: mysql.service: Start request repeated too quickly.
master-at-home systemd[1]: mysql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit mysql.service has entered the 'failed' state with result 'exit-code'.
master-at-home systemd[1]: Failed to start MySQL Community Server.
░░ Subject: A start job for unit mysql.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit mysql.service has finished with a failure.
░░
░░ The job identifier is 4065 and the job result is failed.

我找到了以下行:

 master-at-home mysql-systemd-start[32412]: MySQL configuration not found at /etc/mysql/my.cnf. Please create one.

我根本没有 /etc/mysql/ 子目录。我不知道为什么会这样,以及如何在我的操作系统中恢复 /etc/mysql/my.cnf?

uname -a
Linux master-at-home 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May  7 09:00:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

我决定升级我的操作系统但在消息中收到以下错误:

path# sudo apt-get update
Hit:1 https://artifacts.elastic.co/packages/8.x/apt stable InRelease
Hit:2 http://ua.archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 https://deb.nodesource.com/node_18.x nodistro InRelease
Hit:5 https://ppa.launchpadcontent.net/giuspen/ppa/ubuntu jammy InRelease
Hit:6 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy InRelease
Hit:7 https://ppa.launchpadcontent.net/openswoole/ppa/ubuntu jammy InRelease
Reading package lists... Done
path# sudo apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  php-common php-mcrypt php-mongodb php8.2-mongodb php8.3-mcrypt php8.3-mongodb
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up mysql-server-8.0 (8.0.28-0ubuntu4) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-8.0 (--configure):
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2
Setting up elasticsearch (8.15.3) ...
/usr/share/elasticsearch/bin/elasticsearch-env: line 78: source: /etc/default/elasticsearch: is a directory
dpkg: error processing package elasticsearch (--configure):
 installed elasticsearch package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-8.0; however:
  Package mysql-server-8.0 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-8.0
 elasticsearch
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

这些问题有关联吗?如何解决?

我的 SQL 安装已默认,没有任何特定选项......

更新:

path# sudo apt install --reinstall mysql-server-8.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 6 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for mysql-server-8.0:amd64
path# sudo apt install --reinstall mysql-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 6 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for mysql-server:amd64

更新 # 2:

# sudo apt purge mysql-server-8.0 && sudo apt install --reinstall mysql-server-8.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libcgi-fast-perl libcgi-pm-perl libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
mysql-server* mysql-server-8.0*
0 upgraded, 0 newly installed, 2 to remove and 6 not upgraded.
3 not fully installed or removed.
After this operation, 1 713 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 288059 files and directories currently installed.)
Removing mysql-server (8.0.28-0ubuntu4) ...
Removing mysql-server-8.0 (8.0.28-0ubuntu4) ...
Setting up elasticsearch (8.15.3) ...
/usr/share/elasticsearch/bin/elasticsearch-env: line 78: source: /etc/default/elasticsearch: is a directory
dpkg: error processing package elasticsearch (--configure):
installed elasticsearch package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
elasticsearch
E: Sub-process /usr/bin/dpkg returned an error code (1)

我仍然根本没有 /etc/mysql/ 子目录。

更新 # 3:

我嘟嘟地退出:

whoami
master

运行命令:

master@master-at-home:path$ sudo apt purge elasticsearch && sudo apt install mysql-server-8.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libcgi-fast-perl libcgi-pm-perl libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
elasticsearch*
0 upgraded, 0 newly installed, 1 to remove and 6 not upgraded.
1 not fully installed or removed.
After this operation, 1 179 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 288042 files and directories currently installed.)
Removing elasticsearch (8.15.3) ...
Stopping elasticsearch service... OK
(Reading database ... 286653 files and directories currently installed.)
Purging configuration files for elasticsearch (8.15.3) ...
dpkg: warning: elasticsearch: conffile '/etc/default/elasticsearch' is not a plain file or symlink (= '/etc/default/elasticsearch')
Deleting security auto-configuration directory...OK
dpkg: warning: while removing elasticsearch, directory '/var/lib/elasticsearch' not empty so not removed
dpkg: warning: while removing elasticsearch, directory '/usr/lib/systemd/system' not empty so not removed
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
tinyca
The following NEW packages will be installed:
mysql-server-8.0
0 upgraded, 1 newly installed, 0 to remove and 6 not upgraded.
Need to get 0 B/1 386 kB of archives.
After this operation, 1 603 kB of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 286641 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.28-0ubuntu4_amd64.deb ...
grep: /etc/mysql/: No such file or directory
Unpacking mysql-server-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-server-8.0 (8.0.28-0ubuntu4) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2
Errors were encountered while processing:
mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)
mysql
  • 1 1 个回答
  • 49 Views

1 个回答

  • Voted
  1. Best Answer
    kos
    2024-10-31T12:46:34+08:002024-10-31T12:46:34+08:00

    创建/etc/mysql/mysql.cnf(即使作为一个空文件)并重新安装 MySQL 应该可以工作:

    sudo touch /etc/mysql/mysql.cnf &&
    sudo chmod 0644 /etc/mysql/mysql.cnf &&
    sudo apt install --reinstall mysql-server-8.0
    

    在此之后,我建议将其恢复为文件的默认版本,因为通常会获取和/etc/mysql/mysql.cnf的内容;/etc/mysql/conf.d/etc/mysql/mysql.conf.d

    这是 Ubuntu 24.04.2 上 MySQL 8.0.39 的默认设置/etc/mysql/mysql.cnf(尽管我认为这个文件在各个版本之间都不会改变 - 请记住sudo systemctl restart mysql在恢复文件后运行):

    #
    # 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/
    
    • 1

相关问题

  • 上网本上的 MySQL 数据建模

  • 从终端备份mysql

  • 为什么 /etc/init.d/mysql 会运行错误的暴发户工作?

  • 将引号添加到文件中的字符串

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

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