mysql_secure_installation "Can't connect to local MySQL server through socket"

Since this utility is meant to be used over a standard installation, and because it seems to accept no parameter, I see very few options:

  • temporarily configure MySQL to use the default socket location for the time of the procedure (alternatively, a symbolic link from the default location to your custom location might just work).
  • modify the script mysql_secure_installation so that it uses your custom location. If I understand it correctly, the script creates a temporary configuration file as ./.my.cnf.$$ ($$ is the pid) around line 46 in the make_config subroutine.

Modify as follows: (disclaimer: not tested :)

make_config() {
    echo "# mysql_secure_installation config file" >$config
    echo "[mysql]" >>$config
    echo "user=root" >>$config
    echo "password='$rootpass'" >>$config
    # add the line below
    echo "socket=/home/mysqk123/tmp/mysql.sock" >>$config
}

Again, this script is meant to be used on a standard, out-of-the box installation. Tell your boss (or your client) that if you were able to configure MySQL to use a non-standard socket location, you are also able to run by hand simple commands such as deleting accounts and setting passwords.


Make sure you start mysql or mariadb, for example:

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

The MySQL Socket declaration should be located under [mysqld] in your my.cnf (located at /etc/mysql/my.cnf in Debian flavours). MySQL Socket information can also be found using the following command:

mysql> show variables like 'socket';
+-----------------------------------------+-------------------------------+
| Variable_name                           | Value                         |
+-----------------------------------------+-------------------------------+
| socket                                  | /yourpath/mysql.sock          |
+-----------------------------------------+-------------------------------+
1 rows in set (0.00 sec)

Update the environment variable for the current session and execute the command, eg:

export MYSQL_UNIX_PORT=/home/mysql123/tmp/mysql.sock
./mysql_secure_installation