How to fix: mysql_secure_installation: line 85: .my.cnf.12819: No such file or directory


I installed a LAMP server recently and encountered some strange behavior when I ran the mysql_secure_installation command. Normally I burn through that wizard like nobody's business, but when I get weird messages like these I start wondering what is wrong:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

/usr/bin/mysql_secure_installation: line 85: .my.cnf.12819: No such file or directory

References

Behavior

Here is what I saw when I ran the mysql_secure_installation command from bash:

[root@cloud cloud.domain.tld]# mysql_secure_installation
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
touch: cannot touch `.my.cnf.12819': No such file or directory
touch: cannot touch `.mysql.12819': No such file or directory
chmod: cannot access `.my.cnf.12819': No such file or directory
chmod: cannot access `.mysql.12819': No such file or directory

 


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
/usr/bin/mysql_secure_installation: line 85: .my.cnf.12819: No such file or directory
/usr/bin/mysql_secure_installation: line 86: .my.cnf.12819: No such file or directory
/usr/bin/mysql_secure_installation: line 87: .my.cnf.12819: No such file or directory
/usr/bin/mysql_secure_installation: line 89: .my.cnf.12819: No such file or directory
/usr/bin/mysql_secure_installation: line 58: .mysql.12819: No such file or directory
/usr/bin/mysql_secure_installation: line 60: .mysql.12819: No such file or directory
Enter current password for root (enter for none):

How to get things to work again

Even though my google searches didn't turn anything up when I searched for the mysql_secure_installation error messages, I was able to track down the problem. It happened when I tried to run service mysqld stop and I encountered this error message:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

Once I knew that this was a more general problem I ran a search for the shell-init error and found that this error happens when you run a command from a directory that does not exist anymore. I had just barely deleted & recreated the directory I was in using the GUI, so the bash shell didn't know where it was.

After I cd'd out of the directory and back in, I got mysql_secure_installation (as well as all other commands) to work again.