Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default password of mysql in ubuntu server 16.04

I have installed ubuntu 16.04 server. Mysql server was installed by default in it. When I am trying to access the mysql with mysql -u root -p, I am unable to log in to mysql because I dont have the password. Is there any default password?

I have also tried with --skip-grant-tables, even this does not work. Even trying to log in with just mysql -u root is a failure.

like image 239
Debashisenator Avatar asked Feb 23 '17 16:02

Debashisenator


People also ask

What is default password for MySQL in ubuntu?

In MySQL, by default, the username is root and there's no password. If during the installation process, you accidentally put a password in and don't remember, here is how to reset the password: Stop the MySQL server if it is running, then restart it with the –skip-grant-tables option.

What is the MySQL password by default?

The default user for MySQL is root and by default it has no password.

What is the default password of MySQL in Linux?

There is no default password (empty password) for MySQL database server. You need to assign root password after installing MySQL via yum / rpm command. Some admin set the root password same as the server root password.


2 Answers

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.

like image 116
Maoz Zadok Avatar answered Sep 17 '22 19:09

Maoz Zadok


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 
like image 24
Yasii Avatar answered Sep 20 '22 19:09

Yasii