I just installed mysql-server with the following command
$ sudo apt install mysql-server mysql-client mysql-common
Then when I call the command mysql_secure_installation
MySQL asks to enter the root password:
I haven't set a password for mysql-server and is asking me for it.
How can I set the proper password? Is there a default password?
Best Answer
While the original poster claims to have found a solution to this issue in this answer, it made no sense to me. But now I understand some Debian/Ubuntu distros use a socket-based authentication method. This method of authentication being enabled by default would naturally require one use
sudo
to get into MySQL as they describe.But in general, there is no reason to run
mysql_secure_installation
viasudo
. That makes no sense in most cases since MySQL doesn’t needsudo
for a client transaction like this… Unless socket-based authentication is at play. Andmysql_secure_installation
is just a Bash script that runs a pile of commands in a nice, convenient package to allow updating of some MySQL related security items. Just look at the source code to see what I mean.So if you are on a system that doesn’t use socket-based authentication and you are facing a similar issue, the solution is either the password is blank for older versions of MySQL. So you would just run this to get into MySQL:
Or in the case of
mysql_secure_installation
, just hit Return or Enter when prompted for a password.Or for modern versions of MySQL—I believe MySQL 5.7 or higher—you need to check the error log for a message like this:
This is an example taken from the Persona blog entry on this topic. As to where this MySQL log entry is, it could be in
/var/log/mysqld.log
on a CentOS/RedHat server or it shows up as output from the package install on Ubuntu/Debian systems.But simply checking the error log for the text “temporary password” will provide you with the initial
root
password MySQL sets when it is first installed.