Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default root pasword for MySQL 5.7

Cannot login to MySQL database after fresh install with root ID and empty/no password like other older MySQL versions do

like image 818
Ryan Avatar asked Nov 30 '15 03:11

Ryan


People also ask

What is root password of MySQL & oracle?

Note: Here 'NEW_PASSWORD' is the password of the mysql root user.

What is the root username for MySQL?

In MySQL, by default, the username is root and there's no password.

How do I find my MySQL username and password?

In your local system right, go to this url : http://localhost/phpmyadmin/ In this click mysql default db, after that browser user table to get existing username and password.


2 Answers

There's so many answers out there saying to reinstall mysql or use some combo of

mysqld_safe --skip-grant-tables 

and / or

UPDATE mysql.user SET Password=PASSWORD('password') 

and / or something else ...

... None of it was working for me


Here's what worked for me, on Ubuntu 18.04, from the top

With special credit to this answer for digging me out of the frustration on this ...

$ sudo apt install mysql-server $ sudo cat /etc/mysql/debian.cnf 

Note the lines which read:

user     = debian-sys-maint password = blahblahblah 

Then:

$ mysql -u debian-sys-maint -p Enter password: // type 'blahblahblah', ie. 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;  // When you don't have auto-commit switched on 

Either:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; 

Or:

// For MySQL 5.7+ UPDATE mysql.user SET authentication_string=PASSWORD('new_password') where user='root'; 

Then:

mysql> FLUSH PRIVILEGES; mysql> COMMIT;  // When you don't have auto-commit switched on mysql> EXIT  $ sudo service mysql restart $ mysql -u root -p Enter password: // Yay! 'new_password' now works! 
like image 192
Stewart Avatar answered Oct 13 '22 00:10

Stewart


After you installed MySQL-community-server 5.7 from fresh on linux, you will need to find the temporary password from /var/log/mysqld.log to login as root.

  1. grep 'temporary password' /var/log/mysqld.log
  2. Run mysql_secure_installation to change new password

ref: http://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html

like image 21
Ryan Avatar answered Oct 12 '22 22:10

Ryan