My answer to "i want use password. what should i do?" is:
"no, you probably don't!" (depending on your app's deployment - see comments below)
With Ubuntu 15.10 and later MariaDB installs with the unix_socket user authentication plugin enabled by default: https://mariadb.com/kb/en/mariadb/unix_socket-authentication-plugin/
With a fresh install login with sudo mysql -uroot
and execute:
SELECT User, Password, Host, plugin from mysql.user WHERE user = 'root';
You should see a single user. This also means you cannot remotely login as root with the default install (one of the tasks the mysql_secure_installation
performs).
+------+----------+-----------+-------------+
| User | Password | Host | plugin |
+------+----------+-----------+-------------+
| root | | localhost | unix_socket |
+------+----------+-----------+-------------+
I would recommend leaving this as-is and creating a non-root user with the appropriate permissions for your application to use.
However, if you absolutely need a password-authenticated root user you need to change the plugin to mysql_native_password
.
UPDATE mysql.user SET plugin = 'mysql_native_password', Password = PASSWORD('secret') WHERE User = 'root';
FLUSH PRIVILEGES;
Now quit
then log-in with mysql -uroot -p
.
Note if you need to restart the service you will need to do three commands instead of just sudo systemctl restart mysql
. I am pretty sure there is some addition to a .cnf
file you can make so that restart will work as expected but I couldn't easily figure it out. Basically the lesson is use unix_socket
.
sudo systemctl stop mysql
sudo kill -9 $(pgrep mysql)
sudo systemctl start mysql