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
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.
-
17
-
13
-
5Thanks 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
– cubbukJan 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
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;'
– taconeJul 28, 2017 at 8:39
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;
-
11
-
Worked for me with password=null - setting password to '' did NOT work. I am using MySQL 5.5.12.– joenssonFeb 7, 2014 at 11:31
-
2
update user set password='' where User='root';
work for MySQL 5.6 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– yigalJul 9, 2019 at 7:35
- 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
- login as root and start mysql using
mysql> set password = password('');
Done! No root password.
-
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)– joenssonFeb 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! 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 runset password = password('')
Aug 30, 2018 at 15:56
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');
-
-
6This is now deprecated, use
SET PASSWORD FOR 'root'@'localhost' = '';
instead.– mikiqexJun 23, 2017 at 17:32
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.
-
4It 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.– fluNov 16, 2016 at 10:09
-
1problem with the default Ubuntu 16.04 installation of mysql-server (5.7) is that it uses a different
plugin
(namelyauth_socket
) forroot@localhost
. That's whysudo mysql
will work, whilemysql -uroot
doesn't, since the latter command does not connect via the socket. May 10, 2017 at 8:49
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
-
25This link doesn't actually tell you how to set it to null, which is what the original post was about.– y0mboFeb 10, 2012 at 2:49
-
@y0mbo: Can't you just
update user set password=PASSWORD("") where User='root';
? Feb 10, 2012 at 10:46 -
3Step 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 andupdate user set password=null where User='root';
if using older versions.– mastaziJan 19, 2016 at 1:06 -
1I 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"... :( Jan 24, 2016 at 20:20
-
5@DimitryK The
password
column isauthentication_string
in newer versions.– KrisAug 30, 2016 at 12:53
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;
-
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
This is from MySQL 8.0.13:
use mysql;
update user set authentication_string=null where user='root';
quit;
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.
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';
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.
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.
For connect to mysql without password:
mysql -p
SET PASSWORD = ""
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('');
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
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
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
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
After searching for hours i found it . just Change the password to something contains Upper case numeric and special characters in it.
-
2Welcome 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