How can I delete my password for MySQL? I dont want to have a password to connect to the database. My server is running Ubuntu.
-
Just as a matter of interest, why don't you want a password?– John GardeniersMay 20, 2010 at 2:31
-
For Example I run into errors when I run "dpkg-reconfigure phpmyadmin". It stops with error 1045 with access denied root@localhost "password: no" ending.– user402059Oct 26, 2017 at 13:33
6 Answers
Personally, I think instead it's better to set a password and save it in /root/.my.cnf:
First:
mysqladmin -u root password 'asdfghjkl'
Then edit root's .my.cnf file:
[client]
password = asdfghjkl
Make sure to chmod 0600 .my.cnf
.
Now you have a password but you're no longer prompted for it. My default MySQL server install is a totally random unique password for each MySQL server, saved in the .my.cnf file like this.
-
1I strongly agree with the setting your environment to automatically authenticate you vs removing the password. May 19, 2010 at 23:37
-
3You may need quotes around that password in the .my.cnf. It didn't work for me without. Mar 12, 2011 at 21:07
-
1@user67641: Might depend on version and what's in your password... Mine are all long random strings of alphanumerics (no special characters) and haven't needed quotes.– freiheitMar 12, 2011 at 21:09
-
2If you need to create /root/.my.cnf, it's worth explicitly setting 0600 permissions on it to be sure no other user can snoop. Most of the time normal users can't descend into /root, but the extra paranoia is almost always warranted. Sep 8, 2016 at 16:44
-
Yes, less passwords can be a good thing. But don't just open the database for everybody.
via unix_socket:
grant usage on *.* to 'root'@'localhost' identified via unix_socket;
This gives you passwordless mysql acces for a locally logged in root user. Btw. this is the default in recent ubuntu / debian releases.
some_user@box: mysql -u root # denied
root@box: mysql # good
some_user@box: sudo mysql # good, if "some_user" has sudo rights.
Explanatory slides: https://www.slideshare.net/ottokekalainen/less-passwords-more-security-unix-socket-authentication-and-other-mariadb-hardening-tips.
-
4Welcome to SF! Lovely first answer: clear, a good summary, a link for further exploration, and it adds something to the existing corpus of answers. I'm delighted to be your first upvote, and I hope you stay around to write more answers like this one. Jun 27, 2018 at 9:06
-
1The slides are okay, but this is the actual documentation: mariadb.com/kb/en/library/authentication-plugin-unix-socket– JonnyJDJul 4, 2018 at 15:47
If you DO have a password set for MySQL, follow the instructions at Recover MySQL root Password, and then set your password to null:
For 5.7.6 and later
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'
For 5.7.5 and earlier
update user set password=PASSWORD("") where User='root';
* needs a DB restart (see instructions at the link) for this to take effect.
sudo service mysql restart
-
-
@meyosef - please mark an answer as answered if it solved your problem (click on the green checkmark under the number of votes).– jnevesMay 19, 2010 at 22:52
-
I thought I could use empty password just for Unix socket and not loopback, but it's not possible. The
unix_socket
plugin does a slightly different thing.– basinAug 6, 2018 at 10:20
You can also do:
grant all privileges on *.* to 'root'@'localhost' identified by '';
The IDENTIFIED VIA unix_socket
statement is only for MariaDB.
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED VIA unix_socket;
For MySQL, the same is achieved by IDENTIFIED WITH auth_socket
.
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED WITH auth_socket;
Only a difference of two words, but they're really not the same.
I'm pretty sure that by default there is no password if your the admin user and accessing it locally. Are you finding something different than that?
Does this work?
#> mysqladmin -u root password ''