mysqld:无法读取“/etc/mysql/conf.d/”的目录(OS errno 2 - 没有此文件或目录)

mysqld:无法读取“/etc/mysql/conf.d/”的目录(OS errno 2 - 没有此文件或目录)

我正在尝试使用安装 mysql-server,sudo apt-get install mysql-server但是 apt 说:

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
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)`

在 dpkg 上进行配置后,它说

# sudo dpkg --configure -a
Setting up mysql-server-8.0 (8.0.20-0ubuntu0.20.04.1) ...
Renaming removed key_buffer and myisam-recover options (if present)
ERROR: Unable to start MySQL server:
mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory)
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
Please take a look at https://wiki.debian.org/Teams/MySQL/FAQ for tips on fixing common upgrade issues.
Once the problem is resolved, run apt-get --fix-broken install to retry.
dpkg: error processing package mysql-server-8.0 (--configure):
 installed mysql-server-8.0 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
Errors were encountered while processing:
 mysql-server-8.0
 mysql-server

答案1

打开终端窗口并使用以下方法创建错误消息中提到的目录mkdirp选项。

sudo mkdir -p /etc/mysql/conf.d/

p如果父目录不存在,选项也会创建父目录。

mysql.cnf在上述目录中创建一个新文件并添加[mysql]。也可以使用来完成tee

echo "[mysql]" | sudo tee /etc/mysql/conf.d/mysql.cnf

最后尝试使用重新配置包

sudo dpkg --configure -a

笔记:特别感谢孤儿确认答案的适用性评论

答案2

在我的例子中,mysql 服务器尚未启动,因此使用以下命令之一运行服务器:

五种开始方式:

1. Start MySQL Server
2. sudo service mysql start.
3. sudo /etc/init.d/mysql start.
4. sudo systemctl start mysqld.
5. mysqld.

然后尝试使用 mysql 客户端连接

mysql -u username -p 

那么它工作正常。

相关内容