Score:0

Problem installing MySQL - mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 13 - Permission denied)

br flag

I'm trying to install MySQL using:

sudo apt install mysql-server

and I'm getting the following message at the end of the process:

E: Sub-process /usr/bin/dpkg returned an error code (1)

The whole input/output:

ubuntu@ubuntu:~$ sudo apt install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libfprint-2-tod1 libllvm10 libllvm11 linux-headers-5.4.0-40
  linux-headers-5.4.0-40-generic linux-headers-5.4.0-42
  linux-headers-5.4.0-42-generic linux-headers-5.4.0-45
  linux-headers-5.4.0-45-generic linux-headers-5.4.0-47
  linux-headers-5.4.0-47-generic linux-headers-5.4.0-56
  linux-headers-5.4.0-56-generic linux-headers-5.4.0-60
  linux-headers-5.4.0-60-generic linux-headers-5.4.0-65
  linux-headers-5.4.0-65-generic linux-headers-5.4.0-66
  linux-headers-5.4.0-66-generic linux-headers-5.4.0-67
  linux-headers-5.4.0-67-generic linux-headers-5.4.0-70
  linux-headers-5.4.0-70-generic linux-headers-5.4.0-71
  linux-headers-5.4.0-71-generic linux-headers-5.4.0-72
  linux-headers-5.4.0-72-generic linux-headers-5.4.0-73
  linux-headers-5.4.0-73-generic linux-headers-5.4.0-74
  linux-headers-5.4.0-74-generic linux-headers-5.4.0-77
  linux-headers-5.4.0-77-generic linux-headers-5.4.0-80
  linux-headers-5.4.0-80-generic linux-image-5.4.0-40-generic
  linux-image-5.4.0-42-generic linux-image-5.4.0-45-generic
  linux-image-5.4.0-47-generic linux-image-5.4.0-56-generic
  linux-image-5.4.0-60-generic linux-image-5.4.0-65-generic
  linux-image-5.4.0-66-generic linux-image-5.4.0-67-generic
  linux-image-5.4.0-70-generic linux-image-5.4.0-71-generic
  linux-image-5.4.0-72-generic linux-image-5.4.0-73-generic
  linux-image-5.4.0-74-generic linux-image-5.4.0-77-generic
  linux-image-5.4.0-80-generic linux-modules-5.4.0-40-generic
  linux-modules-5.4.0-42-generic linux-modules-5.4.0-45-generic
  linux-modules-5.4.0-47-generic linux-modules-5.4.0-56-generic
  linux-modules-5.4.0-60-generic linux-modules-5.4.0-65-generic
  linux-modules-5.4.0-66-generic linux-modules-5.4.0-67-generic
  linux-modules-5.4.0-70-generic linux-modules-5.4.0-71-generic
  linux-modules-5.4.0-72-generic linux-modules-5.4.0-73-generic
  linux-modules-5.4.0-74-generic linux-modules-5.4.0-77-generic
  linux-modules-5.4.0-80-generic linux-modules-extra-5.4.0-40-generic
  linux-modules-extra-5.4.0-42-generic linux-modules-extra-5.4.0-45-generic
  linux-modules-extra-5.4.0-47-generic linux-modules-extra-5.4.0-56-generic
  linux-modules-extra-5.4.0-60-generic linux-modules-extra-5.4.0-65-generic
  linux-modules-extra-5.4.0-66-generic linux-modules-extra-5.4.0-67-generic
  linux-modules-extra-5.4.0-70-generic linux-modules-extra-5.4.0-71-generic
  linux-modules-extra-5.4.0-72-generic linux-modules-extra-5.4.0-73-generic
  linux-modules-extra-5.4.0-74-generic linux-modules-extra-5.4.0-77-generic
  linux-modules-extra-5.4.0-80-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libevent-pthreads-2.1-7 mysql-client-8.0 mysql-client-core-8.0
  mysql-server-8.0 mysql-server-core-8.0
Suggested packages:
  mailx tinyca
The following NEW packages will be installed:
  libevent-pthreads-2.1-7 mysql-client-8.0 mysql-client-core-8.0 mysql-server
  mysql-server-8.0 mysql-server-core-8.0
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 24.1 MB of archives.
After this operation, 204 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://security.ubuntu.com/ubuntu focal-security/main amd64 mysql-client-core-8.0 amd64 8.0.26-0ubuntu0.20.04.2 [4222 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 libevent-pthreads-2.1-7 amd64 2.1.11-stable-1 [7372 B]
Get:3 http://security.ubuntu.com/ubuntu focal-security/main amd64 mysql-client-8.0 amd64 8.0.26-0ubuntu0.20.04.2 [22.0 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security/main amd64 mysql-server-core-8.0 amd64 8.0.26-0ubuntu0.20.04.2 [18.5 MB]
Get:5 http://security.ubuntu.com/ubuntu focal-security/main amd64 mysql-server-8.0 amd64 8.0.26-0ubuntu0.20.04.2 [1329 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/main amd64 mysql-server all 8.0.26-0ubuntu0.20.04.2 [9540 B]
Fetched 24.1 MB in 5s (4936 kB/s) 
Preconfiguring packages ...
Selecting previously unselected package mysql-client-core-8.0.
(Reading database ... 881128 files and directories currently installed.)
Preparing to unpack .../0-mysql-client-core-8.0_8.0.26-0ubuntu0.20.04.2_amd64.de
b ...
Unpacking mysql-client-core-8.0 (8.0.26-0ubuntu0.20.04.2) ...
Selecting previously unselected package mysql-client-8.0.
Preparing to unpack .../1-mysql-client-8.0_8.0.26-0ubuntu0.20.04.2_amd64.deb ...
Unpacking mysql-client-8.0 (8.0.26-0ubuntu0.20.04.2) ...
Selecting previously unselected package libevent-pthreads-2.1-7:amd64.
Preparing to unpack .../2-libevent-pthreads-2.1-7_2.1.11-stable-1_amd64.deb ...
Unpacking libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ...
Selecting previously unselected package mysql-server-core-8.0.
Preparing to unpack .../3-mysql-server-core-8.0_8.0.26-0ubuntu0.20.04.2_amd64.de
b ...
Unpacking mysql-server-core-8.0 (8.0.26-0ubuntu0.20.04.2) ...
Selecting previously unselected package mysql-server-8.0.
Preparing to unpack .../4-mysql-server-8.0_8.0.26-0ubuntu0.20.04.2_amd64.deb ...
grep: /etc/mysql/: No such file or directory
Unpacking mysql-server-8.0 (8.0.26-0ubuntu0.20.04.2) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../5-mysql-server_8.0.26-0ubuntu0.20.04.2_all.deb ...
Unpacking mysql-server (8.0.26-0ubuntu0.20.04.2) ...
Setting up mysql-client-core-8.0 (8.0.26-0ubuntu0.20.04.2) ...
Setting up mysql-client-8.0 (8.0.26-0ubuntu0.20.04.2) ...
Setting up libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ...
Setting up mysql-server-core-8.0 (8.0.26-0ubuntu0.20.04.2) ...
Setting up mysql-server-8.0 (8.0.26-0ubuntu0.20.04.2) ...

Configuration file '/etc/mysql/mysql.conf.d/mysqld.cnf'
 ==> Deleted (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** mysqld.cnf (Y/I/N/O/D/Z) [default=N] ? 
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
No apport report written because the error message indicates its a followup erro
r from a previous failure.
                          dpkg: dependency problems prevent configuration of mys
ql-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
Processing triggers for systemd (245.4-4ubuntu3.11) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Errors were encountered while processing:
 mysql-server-8.0
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

When I run sudo mysql, I get this error:

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

And when I run systemctl status mysql, I get this output:

mysql.service - MySQL Community Server

Loaded: loaded (/lib/systemd/system/mysql.service; disabled; ve>

Active: inactive (dead)

Any advice would be appreciated.

user535733 avatar
cn flag
dpkg `error code (1)` merely means that something went wrong with some subsidiary script, which is not enough information to offer useful advice. Please edit your question to show us the complete input and output.
in flag
Has MySQL been installed on this machine in the past, then re-installed?
BlueSkies avatar
br flag
@matigo, MySQL was installed and then removed on this machine in the past.
Andrew Mititi avatar
cn flag
The problem might be because of the previous mysql installation. **Just a word of advice** Try docker and you will change preference of how you install this kind of service. WIth docker you will only be required to pull the image, expose the mysql port to the host machine and set the restart policy to always. Let docker do its thing and that is it. Within seconds you will have mysql installed and exposed on the normal localhost port
Score:0
in flag

Because MySQL was installed at some point in the past, there are likely empty directories or fragments of configuration files from that previous installation interfering with the new one. When MySQL is installed, it looks for the existence of certain directories. If they do not exist, then they're created and populated. If they do exist, then they're left alone with the expectation that the startup scripts will find the previous files, perform any upgrades, and carry on from there.

With this said, the simplest way to resolve this issue would be to — once again — remove MySQL. Here is a complete list of steps:

  1. Open Terminal or SSH into the machine
  2. Ensure the MySQL service is not running (which is probably isn't):
    sudo service mysql stop 
    
  3. Remove anything and everything related to MySQL:
    sudo apt purge mysql-server mysql-common mysql-server-core-* mysql-client-core-*
    
  4. Ensure there are no database files and the default data directory is gone:
    sudo rm -Rf /var/lib/mysql/
    
  5. Ensure the default configuration directory is gone:
    sudo rm -Rf /etc/mysql/
    
  6. Ensure the default log file directory is gone:
    sudo rm -Rf /var/log/mysql
    
  7. Re-install MySQL:
    sudo apt install mysql-server
    

This should give you a fully operational MySQL installation

BlueSkies avatar
br flag
No luck. Re-install MySQL gives error messages: `ERROR: Unable to start MySQL server: mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 13 - Permission denied) mysqld: [ERROR] Fatal error in defaults handling. Program aborted!`
Score:0
ru flag
pgh

I ran into this error ("Can't read dir of '/etc/mysql/conf.d/'") while attempting to install mysql-server_5.7.35-1ubuntu18.04_i386.deb on an old ideapad on which mysql previously had been installed and removed. Turned out that there was no '/conf.d/' directory under '/etc/mysql' but there was a '/mysql.conf.d/' directory there (which contained a 'mysqld.cnf' file. I simply renamed the '/mysql.conf.d/' directory to '/conf.d/' and the installation thereafter proceeded without any error. Do not know why. Hope this helps.

BlueSkies avatar
br flag
**Both** `/etc/mysql/conf.d` and `/etc/mysql/mysql.conf.d` **exist**, so it must be a different problem.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.