My issue resembles this one, this, and this but is not the same. It includes this problem.

I am installing mySQL on a fresh Ubuntu 22.04 per this guide from DigitalOcean.

It is very straightforward, mostly just apt install everything including mysql-server, and I have followed it exactly except for using apt-get. However some inconsistencies appeared:

  • After apt install mysql-server, I am unable to run sudo mysql_secure_installation. After entering a password for the mySQL root user, I got this error mentioned earlier which was solved by the solution in that answer, which is to run sudo mysql and ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'supersecretpassword'; after which I can finish sudo mysql_secure_installation.

Now, the guide indicates I should be able to run sudo mysql with no user or password. I can't. I can run sudo mysql -p and only if I provide the mySQL root user password at the prompt.

The guide even adds this comment:

...you didn’t need to provide a password to connect as the [mySQL] root user, even though you have defined one when running the mysql_secure_installation script. That is because the default authentication method for the administrative MySQL user is unix_socket instead of password.

Not for me. In fact if I try to run sudo mysql -u unix_socket or add -p, I cannot log in.

Why is mySQL behaving differently for me? Does this indicate a specific problem? I have replicated this issue on 5 different machines, all fresh installs of 22.04 and apt-get upated.

  • I haven't done the above in a long time. But, based on how you asked your question, you're assuming that DigitalOcean is correct -- as if it's a gold standard. It's possible it is wrong. Since it is a fresh install that you've also replicated 5 times, my conclusion from what you've described is just that DigitalOcean is wrong. That is, rather than asking why what you're seeing doesn't match online information, you should just ask how to enable passwordless access of MySQL. As an aside, is having the password in a file an acceptable solution for you?
    – Ray
    Nov 30, 2022 at 20:52
  • I meant by having a .my.cnf file.
    – Ray
    Nov 30, 2022 at 20:53
  • you do not use sudo mysql you use sudo -i and use a # to start mysql command line, Then setup mysql by adding your use to use and edit my.cnf to match that.
    – Rinzwind
    Nov 30, 2022 at 20:58
  • Ray, thanks for your comment, I'll live with this conclusion of the blog being wrong, after all they make duplicate articles for different ubuntu versions and software stacks and likely copy-paste old sections. I followed your suggestion regarding .my.cnf as well, and it works, though I suspect I'll need a well-thought-out system of users and access levels now. Rinzwind, thanks also, I don't understand but I suspect that is because your comment is condensed ideas that are new to me.
    – Wiley Rush
    Nov 30, 2022 at 23:01
  • @WileyRush were you able to complete the installation of MySQL? Or are you still looking for an answer that will allow you to install the database engine and have it properly configured?
    – matigo
    Dec 1, 2022 at 0:31


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.