65

How can I change the password for root user of MySQL to null -- meaning no password or '' -- from the MySQL command line client?

22 Answers 22

94

Worked for me and "5.7.11 MySQL Community Server":

use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';

I had to change the 'plugin' field as well because it was set to 'auth_socket'.

After that I could connect as mysql -u root without a password.

6
  • 17
    plugin='mysql_native_password' was the key bit for me.
    – Kris
    Aug 30, 2016 at 13:01
  • 13
    I needed to do flush privileges afterwards too.
    – Kris
    Jan 16, 2017 at 10:56
  • 5
    Thanks worked for me in 5.17, you need to restart mysql after using this method to see the affects of changes. sudo service mysql restart
    – cubbuk
    Jan 20, 2017 at 11:55
  • This worked on mysql Ver 15.1 Distrib 10.0.28-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
    – Andrew Wei
    Jan 24, 2017 at 15:32
  • Weird enough, I have to do this after each upgrade of mysql. That said, this is my one liner: sudo mysql -uroot mysql -e 'update user set authentication_string=password(""), plugin="mysql_native_password" where user="root";flush privileges;'
    – tacone
    Jul 28, 2017 at 8:39
57

If you want an empty password, you should set the password to null and not use the Password hash function, as such:

On the command line:

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -uroot

In MySQL:

use mysql;
update user set password=null where User='root';
flush privileges;
quit;
5
  • 11
    Error Code: 1048. Column 'Password' cannot be null Jun 11, 2013 at 22:39
  • Worked for me with password=null - setting password to '' did NOT work. I am using MySQL 5.5.12.
    – joensson
    Feb 7, 2014 at 11:31
  • 2
    update user set password='' where User='root'; work for MySQL 5.6
    – G. Demecki
    Jul 27, 2015 at 11:39
  • I think Zendo June's answer is the best solution for this case. Sep 27, 2017 at 19:04
  • flush privileges; is a must - conclusion after an hour of hacking around
    – yigal
    Jul 9, 2019 at 7:35
53
  • connect to mysql as user root (use one of the two following methods)
    • login as root and start mysql using mysql -p, enter current root password
    • login as self and start mysql using mysql -u root -p, enter current root password
  • mysql> set password = password('');

Done! No root password.

3
  • This did not work for me, I was unable to login as root afterwards no matter if I provided password or not. Setting password to null instead of '' worked for me. (Mysql 5.5.12)
    – joensson
    Feb 7, 2014 at 11:31
  • Worked for me on MariaDB 10.3.9 - much easier than a lot of the advice about stopping the database, running with skip-grant-tables, etc etc!
    – Codemonkey
    Aug 29, 2018 at 11:47
  • Thank you. Worked for me with MariaDB 10.3.8. May be obvious but mysql> in the last step is the prompt. You actually just run set password = password('') Aug 30, 2018 at 15:56
21
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');
2
  • This is a more up-to-date answer
    – Kip Diskin
    Jan 6, 2016 at 5:06
  • 6
    This is now deprecated, use SET PASSWORD FOR 'root'@'localhost' = ''; instead.
    – mikiqex
    Jun 23, 2017 at 17:32
16

This worked for me on Ubuntu 16.04 with v5.7.15 MySQL:

First, make sure you have mysql-client installed (sudo apt-get install mysql-client).

Open terminal and login:

mysql -uroot -p

(then type your password)

After that:

use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';

(tnx @Stanislav Karakhanov)

And the very last important thing is to reset mysql service:

sudo service mysql restart

You should now be able to login (without passsword) also by using MySQL Workbench.

2
  • 4
    It baffles me how many different ways there are to set the root password. None of them worked on my MySql 5.7.16 until this solution came along. Thank you.
    – flu
    Nov 16, 2016 at 10:09
  • 1
    problem with the default Ubuntu 16.04 installation of mysql-server (5.7) is that it uses a different plugin (namely auth_socket) for root@localhost. That's why sudo mysql will work, while mysql -uroot doesn't, since the latter command does not connect via the socket. May 10, 2017 at 8:49
15

You can recover MySQL database server password with following five easy steps.

Step # 1: Stop the MySQL server process.

Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.

Step # 3: Connect to mysql server as the root user.

Step # 4: Setup new mysql root account password i.e. reset mysql password.

Step # 5: Exit and restart the MySQL server.

Here are commands you need to type for each step (login as the root user):

Step # 1 : Stop mysql service

# /etc/init.d/mysql stop

Output:

Stopping MySQL database server: mysqld.

Step # 2: Start to MySQL server w/o password:

# mysqld_safe --skip-grant-tables &

Output:

[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

Step # 3: Connect to mysql server using mysql client:

# mysql -u root

Output:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

Step # 4: Setup new MySQL root user password

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Step # 5: Stop MySQL Server:

# /etc/init.d/mysql stop

Output:

Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+  Done                    mysqld_safe --skip-grant-tables

Step # 6: Start MySQL server and test it

# /etc/init.d/mysql start
# mysql      
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 
# mysql -u root -p

Source: http://www.cyberciti.biz/tips/recover-mysql-root-password.html

8
  • 25
    This link doesn't actually tell you how to set it to null, which is what the original post was about.
    – y0mbo
    Feb 10, 2012 at 2:49
  • @y0mbo: Can't you just update user set password=PASSWORD("") where User='root';? Feb 10, 2012 at 10:46
  • 3
    Step 1 and 2 are not necessary (the question doesn't say that the previous password was lost or forgotten), step 4 is wrong because the question asks how to set a blank password, it should be update user set password=PASSWORD('') where User='root'; if using MySQL 5.5.46 or newer and update user set password=null where User='root'; if using older versions.
    – mastazi
    Jan 19, 2016 at 1:06
  • 1
    I come again a long time after this issue was created but with MariaDB 10.0.22 it does not work at all, either with "password=PASSWORD('')" or "password=null"... :(
    – Alex Rock
    Jan 24, 2016 at 20:20
  • 5
    @DimitryK The password column is authentication_string in newer versions.
    – Kris
    Aug 30, 2016 at 12:53
8

For MySQL 8.0 just:

SET PASSWORD FOR 'root'@'localhost' = '';

7

It's not a good idea to edit mysql database directly.

I prefer the following steps:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY ''; 
mysql> flush privileges;
1
  • This also works in case you get the following error: ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. Sep 27, 2017 at 19:02
4

This is from MySQL 8.0.13:

use mysql;

update user set authentication_string=null  where user='root';

quit;
0
3

I noticed a few of these solutions above are now deprecated.

To set an empty password simply follow these steps:

mysql -u root -p

use mysql

SET PASSWORD FOR 'root'@'localhost' = '';

\q (to quit)

now run: mysql -u root

You should be able to start mysql up without a password now.

0
3

It works for me.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'
0
2

The answer by user64141

use mysql;
update user set password=null where User='root';
flush privileges;
quit;

didn't work for me in MariaDB 10.1.5 (supposed to be a drop in replacement for MySQL). While didn't tested it in MySQL 5.6 to see if is an upstream change, the error I got was:

ERROR 1048 (23000): Column 'Password' cannot be null

But replacing the null with empty single or double quotes worked fine.

update user set password='' where User='root';

or

update user set password="" where User='root';
1

I am using nodejs and windows 10. A combination of two answers worked for me.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY ''; 
mysql> flush privileges;

followed by:

restart;

Hope this helps for others who still have an issue with this.

1
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
0

If you know your Root Password and just wish to reset it then do as below:

  • Start MySQL Service from control panel > Administrative Tools > Services. (only if it was stopped by you earlier ! Otherwise, just skip this step)

  • Start MySQL Workbench

  • Type in this command/SQL line

    ALTER USER 'root'@'localhost' PASSWORD EXPIRE;

To reset any other user password... just type other user name instead of root.

0

For connect to mysql without password:

mysql -p SET PASSWORD = ""

https://dev.mysql.com/doc/refman/5.7/en/set-password.html

0

The syntax is slightly different depending on version. From the docs here: https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

MySQL 5.7.6 and later:

ALTER USER 'root'@'localhost' IDENTIFIED BY '';

MySQL 5.7.5 and earlier:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');
0

My variant for MySQL 5.7:

Stop service mysql:

$ sudo service mysql stop

Running in Safe Mode:

$ sudo mysqld_safe --skip-grant-tables --skip-networking

(above line is the whole command)

Open a new terminal window:

$ mysql -u root

$ mysql use mysql;

$ mysql update user set authentication_string=password('password') where user='root';

$ mysql update user set plugin="mysql_native_password" where User='root';

$ mysql flush privileges;
$ mysql quit;

Run the mysql service:

$ sudo service mysql start
0

Wanted to put my own 2cents in here bcuz the above answers did not work for me. On centos 7, mysql community v8, shell is bash.

The correct commands would be as follows:

# start mysql without password checking
systemctl stop mysqld 2>/dev/null
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" &&
systemctl start mysqld

# set default password to nothing
mysql -u root mysql <<- 'EOF'
    FLUSH PRIVILEGES;
    UNINSTALL COMPONENT 'file://component_validate_password';
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
    FLUSH PRIVILEGES;
    INSTALL COMPONENT 'file://component_validate_password';
EOF

# restart mysql normally
systemctl restart mysqld

then you can login without password:

mysql -u root
0

its all because you installed greater then 5.6 version of the mysql

Solutions

1.you can degrade mysql version solution

2 reconfigure authentication to native type or legacy type authentication using
configure option

0

On ubuntu 19.10, mysql 8, this is what worked for me:

$ sudo mysqld --skip-grant-tables &
$ mysql
> use mysql
> alter user set authentication_string='', plugin='mysql_native_password' where user = 'root';
> quit
$ sudo mysqladmin shutdown
$ sudo systemctl start mysql

If you get errors trying to run mysqld_safe, in particular: /var/run/mysqld for UNIX socket file don't exists, you can try creating the dir and running mysqld_safe again.

$ sudo mkdir /var/run/mysqld
$ sudo chown mysql /var/run/mysqld
$ sudo chgrp mysql /var/run/mysqld
1
  • It's UPDATE user not ALTER user.
    – chx
    Oct 25, 2021 at 19:06
-2

After searching for hours i found it . just Change the password to something contains Upper case numeric and special characters in it.

1
  • 2
    Welcome to Stack Overflow. Did you read where the question asks how to set the root password to null, and the many existing answers that show that it can be done rather than changing the password to something that isn't null? Aug 26, 2019 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.