I installed mysql-server via
apt install mysql-server. It seemed to go fine. However, when I enter
sudo mysql to set up a root password, I get:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Which is interesting, because none of the documentation I’ve seen says that I need a password. I tried
sudo mysql -u root -p and hit Enter at the password prompt, but I got the same result.
Next, I decided to try
sudo mysql_secure_installation. No luck - it asked me for the root password, which I had not yet been able to create. Hitting Enter got me:
Error: Access denied for user 'root'@'localhost' (using password: NO)
I.e., the same message with a different prefix.
I dug a little bit and found the suggestion to stop the service and start it with mysqld_safe. That failed in a different way:
 17293 ~: 2022-06-20T00:07:01.652212Z mysqld_safe Logging to '/var/log/mysql/error.log'. 2022-06-20T00:07:01.654424Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.  + done sudo mysqld_safe –skip-grant-tables –skip-networking
And indeed, /var/run/mysqld don’t exists. I created it and tried again:
 17776 ~: 2022-06-20T00:13:33.123633Z mysqld_safe Logging to '/var/log/mysql/error.log'. 2022-06-20T00:13:33.154910Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 2022-06-20T00:13:35.950220Z mysqld_safe mysqld from pid file /var/lib/mysql/ocean.pid ended  + done sudo mysqld_safe –skip-grant-tables –skip-networking
It took roughly a second to start and then end. /var/log/mysql/error.log had no new messages. /var/lib/mysql/ocean.pid was nowhere to be found.
Finally, I tried a suggestion that had me updating the contents of /etc/mysql/my.cnf. All of the commands - mysql, mysql_secure_installation, mysqld_safe - gave the same results, so I reset the my.cnf file to its former state.
To summarize, thus far I simply can’t use MySQL, because it’s asking for a root password that it won’t let me create. Any thoughts out there about what might be going on?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.