[mysql] How to set root password to null

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

This question is related to mysql mysql-management

The answer is


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;

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('');

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.


It works for me.

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


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';

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

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;

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


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

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.


This is from MySQL 8.0.13:

use mysql;

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

quit;

  • 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.


For MySQL 8.0 just:

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


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.


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

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

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.


For connect to mysql without password:

mysql -p SET PASSWORD = ""

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


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


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.