Software & AppsOperating SystemLinux

How To Fix “Can’t read dir of ‘/etc/mysql/conf.d/'” Error When Installing MySQL on Ubuntu 20.04

Ubuntu 19

In this article, we will walk you through the steps to fix the error Can't read dir of '/etc/mysql/conf.d/' that you may encounter when installing MySQL on Ubuntu 20.04. This error typically arises when the directory /etc/mysql/conf.d/ does not exist on your system.

Quick Answer

To fix the "Can’t read dir of ‘/etc/mysql/conf.d/’" error when installing MySQL on Ubuntu 20.04, you need to create the missing directory /etc/mysql/conf.d/ using the mkdir command, create a configuration file named mysql.cnf in the directory using the echo and tee commands, and then reconfigure the packages using the dpkg command. If the issue persists, you can try starting the MySQL server manually using one of the provided methods.

Understanding the Error

The error mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory) indicates that the MySQL server is unable to find or read the directory /etc/mysql/conf.d/. This directory is where MySQL expects to find configuration files, and if it doesn’t exist, MySQL throws an error.

Steps to Fix the Error

Step 1: Creating the Missing Directory

The first step in resolving this error is to create the missing directory. You can do this using the mkdir command, which is used to create directories in Linux. The -p option is used to create parent directories as needed. Here’s the command:

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

Step 2: Creating a Configuration File

Next, you need to create a new configuration file named mysql.cnf in the /etc/mysql/conf.d/ directory. You can use the echo command to output the string [mysql] and the tee command to write this output to mysql.cnf. Here’s the command:

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

Step 3: Reconfiguring the Packages

After creating the directory and the configuration file, you should reconfigure the packages using the dpkg command. The --configure -a option is used to configure all packages that are unpacked but not yet configured. Here’s the command:

sudo dpkg --configure -a

Starting the MySQL Server

If the above steps don’t resolve the issue, you can try starting the MySQL server manually. Here are five different ways to start the server:

Method 1: Using the service command

sudo service mysql start

Method 2: Using the init.d directory

sudo /etc/init.d/mysql start

Method 3: Using the systemctl command

sudo systemctl start mysqld

Method 4: Using the mysqld command

mysqld

Method 5: Using the mysqld command with sudo

sudo mysqld

Connecting to the MySQL Server

After starting the MySQL server, you can try connecting to it using the mysql client:

mysql -u username -p

Please note that you need to replace username with your actual MySQL username.

Conclusion

In this article, we discussed how to fix the error Can't read dir of '/etc/mysql/conf.d/' when installing MySQL on Ubuntu 20.04. We hope that this guide has been helpful. If you are still facing the issue, try running sudo apt update to check for any errors and follow the recommendations provided.

What is the purpose of the `/etc/mysql/conf.d/` directory?

The /etc/mysql/conf.d/ directory is where MySQL expects to find configuration files. It is used to store additional configuration files that can be included in the main MySQL configuration file.

How do I create a directory in Linux?

To create a directory in Linux, you can use the mkdir command followed by the directory name. For example, to create a directory named mydirectory, you would run mkdir mydirectory.

Leave a Comment

Your email address will not be published. Required fields are marked *