There are two main reasons why mysql_secure_installation
might fail with a permissions issue:
- Incorrect Authentication Plugin: By default, some MySQL installations might use the
auth_socket
plugin, which doesn't require a password by default.mysql_secure_installation
expects a password and won't work with this setup. - Insufficient Privileges: Even with a password-based plugin, your user account might lack the necessary privileges to modify root user access. This could be due to:
- You're not logged in as the root user.
- The root user doesn't have the required permissions (unlikely, but possible).
Are you using Digital Ocean?
I had this issue when trying to run this command after installing the ghost 1 click installer.
When your'e logged into Digital Ocean as root run the commands shown below:
$ cat ~/.digitalocean_password
# see the password, then do:
$ sudo mysql_secure_installation
Configuring DigitalOcean 1-Click Ghost installation.
Please wait a minute while your 1-Click is configured.
Once complete, you are encouraged to run mysql_secure_installation to ready
your server for production.
Then enter the password that was shown in the bash console.
You also will have to switch to the ghost-mgr user to manage Ghost via the CLI:
sudo -i -u ghost-mgr
Further resources that you can check out:
- Stack Overflow discussion on similar issue: https://stackoverflow.com/questions/59481975/mysql-secure-installation-problem-access-denied-for-user-rootlocalhost
- MySQL documentation on user privileges (might vary slightly depending on your version): https://dev.mysql.com/doc/refman/8.0/en/create-user.html