Default password of mysql in ubuntu server 16.04
This is what you are looking for:sudo mysql --defaults-file=/etc/mysql/debian.cnf
MySql on Debian-base Linux usually use a configuration file with the credentials.
I had a fresh installation of mysql-server
on Ubuntu 18.10 and couldn't login with default password. Then only I got to know that by default root user is authenticated using auth_socket
. So as in the answer when the plugin changed to mysql_native_password
, we can use mysql default password
$ sudo apt install mysql-server
$ sudo cat /etc/mysql/debian.cnf
You can find the following lines in there
user = debian-sys-maint
password = password_for_the_user
Then:
$ mysql -u debian-sys-maint -p
Enter password:
type the password from debian.cnf
mysql> USE mysql
mysql> SELECT User, Host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| User | Host | plugin |
+------------------+-----------+-----------------------+
| root | localhost | auth_socket |
| mysql.session | localhost | mysql_native_password |
| mysql.sys | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> COMMIT;
Either:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Or:
// For MySQL 5.7+
mysql>UPDATE mysql.user SET authentication_string=PASSWORD('new_password') where user='root';
--Update--
Sometimes you will need to restart your mysql server.
sudo service mysql restart
or
sudo systemctl restart mysql
Mysql by default has root user's authentication plugin as auth_socket
, which requires the system user name and db user name to be the same.
Specifically, log in as root or sudo -i
and just type mysql
and you will be logged in as mysql root
, you can then create other operating users.
If you do not have a root on host, I guess you should not be allowed to login to mysql as root?
Although this is an old question, there are several of us still struggle to find an answer. At least I did. Please don't follow all the lengthy solutions. You could simply login to your mysql as root without providing any password (provided it is a fresh installation or you haven't changed the password since your installation) by adding sudo before your mysql command.
$sudo mysql -uroot -p
mysql>
This is because mysql changed the security model in one of the latest versions.
Hope this helps
You can simply reset the root password by running the server with --skip-grant-tables and logging in without a password by running the following as root or with sudo:
service mysql stop
mysqld_safe --skip-grant-tables &
mysql -u root
mysql> use mysql;
mysql> update user set authentication_string=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
# service mysql stop
# service mysql start
$ mysql -u root -p