How to Solve Error Message mysqld: Can’t change dir to ‘/opt/mysql/temp/mysql-5.7.28-linux-glibc2.12-x86_64/data/’ (Errcode: 13 – Permission denied)

Posted on

Introduction

This is an article where the main focus is just to get the solution for handling an error message. The error message exists as in the title of this article. The error above occurs open executing a certain command. It is actually has a strong connection with the article in this link. In that link, there is an article with the title of ‘How to Solve Error Message The data directory needs to be specified in initializing MySQL Data Directory’. It is actually a process for generating data directory for MySQL Database Server. Before MySQL Database Server available for further usage, the existance of data directory is a must.  So, after specifying the location of the data directory, there is another error occur. The following is the execution of that command along with the error message which appear in the middle of the execution process :

root@hostname:/opt/mysql/temporary/mysql-5.7.28-linux-glibc2.12-x86_64/bin# ./mysql_install_db --datadir=/opt/mysql/temporary/mysql-5.7.28-linux-glibc2.12-x86_64/data
2020-01-06 15:30:13 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-01-06 15:30:13 [ERROR]   Child process: /opt/mysql/temp/mysql-5.7.28-linux-glibc2.12-x86_64/bin/mysqldterminated prematurely with errno= 32
2020-01-06 15:30:13 [ERROR]   Failed to execute /opt/mysql/temp/mysql-5.7.28-linux-glibc2.12-x86_64/bin/mysqld --bootstrap --datadir=/opt/mysql/temp/mysql-5.7.28-linux-glibc2.12-x86_64/data --lc-messages-dir=/usr/share/mysql --lc-messages=en_US
-- server log begin --
mysqld: Can't change dir to '/opt/mysql/temporary/mysql-5.7.28-linux-glibc2.12-x86_64/data/' (Errcode: 13 - Permission denied)
2020-01-06T08:30:13.644273Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2020-01-06T08:30:13.648317Z 0 [ERROR] failed to set datadir to /opt/mysql/temporary/mysql-5.7.28-linux-glibc2.12-x86_64/data/
2020-01-06T08:30:13.648347Z 0 [ERROR] Aborting


-- server log end --
root@hostname:/opt/mysql/temporary/mysql-5.7.28-linux-glibc2.12-x86_64/bin#

The command above is ‘mysql_install_db’ and there is an additional parameter specifying the location of the data directory. But the reason of the above command end in failure is because the owner of the ‘data’ directory is not ‘mysql’. This is is an article where the main focus is just to get the solution for handling an error message. The error message exists as in the title of this article. So, in order to solve the problem, the following is actually the step to execute :

1. If there is no ‘data’ folder before, make sure that the ownership of the root folder where the data exist belong to ‘mysql’ user account. For an example, the folder of ‘mysql/temp/data’ has ‘mysql’ as the owner.

2. Moreover, if the ‘data’ folder is already exist, make sure that the ‘data’ folder has ‘mysql’ as the owner.

3. Finally, execute the following command to be able to generate data directory using an additional parameter of ‘–user=mysql’.

root@hostname:/opt/mysql/temporary/mysql-5.7.28-linux-glibc2.12-x86_64/bin# ./mysql_install_db --user=mysql --datadir=/opt/mysql/temporary/mysql-5.7.28-linux-glibc2.12-x86_64/data
2020-01-06 15:30:56 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-01-06 15:31:26 [WARNING] select() timed out.
root@hostname:/opt/mysql/temporary/mysql-5.7.28-linux-glibc2.12-x86_64/bin# 

Leave a Reply