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 runsudo 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 runsudo mysql
andALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'supersecretpassword';
after which I can finishsudo 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.
.my.cnf
file.sudo mysql
you usesudo -i
and use a#
to startmysql
command line, Then setup mysql by adding your use to use and edit my.cnf to match that.