How to find out my MySQL password for MySQL?

I just installed MySQL on Ubuntu and the root user cannot log in :)

How can I recover or find out my password? Using a space for a password does not work.

+65
mysql ubuntu
Apr 15 2018-11-11T00:
source share
10 answers

You can reset the root password by starting the server with --skip-grant-tables and logging in without a password by running as the root user (or using 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 

Now you can log in as root with your new password.

In addition, you can find the request, reset the password in the /home/$USER/.mysql_history or /root/.mysql_history user, reset the password, but the above will always work.

Note: before MySQL 5.7, the column was called password and not authentication_string . Replace the line above

 mysql> update user set password=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root'; 
+134
Apr 15 2018-11-11T00:
source share

I understand that this is an old thread, but I thought I was updating it with my results.

Alex, it looks like you installed the MySQL server through the mysql-server meta-package. This installs the last package by reference (in my case, mysql-server-5.5). I, like you, have not been asked to enter the MySQL password during setup, as I expected. I suppose there are two answers:

Solution # 1: install MySQL by name:

 $ sudo apt-get install mysql-server-5.5 

or

Solution # 2: reconfigure the package ...

 $ sudo dpkg-reconfigure mysql-server-5.5 

You must specify the full name of the package. Using the "mysql-server" meta-package did not have the desired result for me. Hope this helps someone :)

Link: https://help.ubuntu.com/12.04/serverguide/mysql.html

+19
May 01 '13 at 5:51
source share
 sudo mysql -u root ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_PASSWORD_HERE'; FLUSH PRIVILEGES; mysql -u root -p # and it works 
+8
Jun 11 '18 at 11:24
source share

MySQL 5.5 on Ubuntu 14.04 required several different commands, recommended here . In a nutshell:

 sudo /etc/init.d/mysql stop sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking & mysql -u root 

And then from the MySQL prompt

 FLUSH PRIVILEGES; SET PASSWORD FOR root@'localhost' = PASSWORD('password'); UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root'; FLUSH PRIVILEGES; 

And the quoted source also offers an alternative method.

+7
Jul 09 '14 at 1:14
source share

For RHEL-mysql 5.5:

 /etc/init.d/mysql stop /etc/init.d/mysql start --skip-grant-tables mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root'; mysql> FLUSH PRIVILEGES; mysql> exit; mysql -uroot -pnewpwd mysql> 
+3
Mar 02 '15 at 6:52
source share
+1
Apr 15 2018-11-11T00:
source share

Hmm Mysql 5.7.13 to reset all I did was:

$ sudo service mysql stop To stop mysql

$ mysqld_safe --skip-grant-tables & Run mysql

$ mysql -u root

Like the correct answer. Then all I did was do what @eebbesen did.

mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('NEW-password-HERE');

Hope this helps anyone :)

+1
Sep 27 '16 at 17:56
source share

There is a simple solution.

MySql 5.7 comes with an anonymous user, so you need to reconfigure the MySQL server.

You can do this with this command.

try to find a temporary passage:

 grep 'temporary password' /var/log/mysqld.log 

then:

 sudo mysql_secure_installation 

This link has more information about MySQL 5.7

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

+1
Jan 16 '19 at 19:17
source share

According to MYSQL 5.7, if you use mysql for development purposes, simply:

1.kill mysql:

 $ sudo service mysql stop 

2.start mysql in -skip-grant-tables mode:

 $ sudo mysqld_safe --skip-grant-tables 

and besides, you can try to change the user table in the “skip-grant-table” mode, however I failed.

so, this is just a workaround.

0
Jun 28 '16 at 8:07
source share

It is actually very simple. You do not have to go through many things. Just run the following command in the terminal and follow the instructions on the screen.

 sudo mysql_secure_installation 
0
Aug 24 '19 at 8:17
source share



All Articles