Debian – MySQL root account without password

debianMySQLroot

I've just installed MySQL server with no password on root account. I was prompted to enter root password 3 times and I left it blank all three times because I don't want to use password. But now it seems to me that may not be such a great idea.

I try to connect from Workbench (with now password entered) and I get error: Access denied for user 'root'@'localhost'.
Why if there is no password??

I realize now, that if I only have had provided some dummy password on installation I would have no problems no, so I try to set it by typing: mysqladmin -u root -p password; enter blank password, and again, get the following:

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost'

If I just type "mysql" into console I get:

Access denied for user 'me'@'localhost' (using password: NO)

If I can have root account without password, and if I won't have much problems in that case, than I'd like to leave it without pass, but if that isn't good, than please tell me how set password.
And if it's good to leave it without password then please tell me how to connect without pass 🙂

EDIT:
Linux distro: Mint Cinnamon 64-bit;
MySQL version: 5.7

Best Answer

By default Debian/Ubuntu/Mint has a user with administrative accesses, namely used to shutdown MySQL, called debian-sys-maint.

Go to the file /etc/mysql/debian.cnf which has as the format:

[client]
host     = localhost
user     = debian-sys-maint
password = XXXXXXXX
socket   = /var/run/mysqld/mysqld.sock 

Take from there the password, that is randomly generated when installing MySQL (e.g. it differs between servers);

And login into your MySQL with:

mysql -udebian-sys-maint -pXXXXXXXX

After that, you can change your root password.

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

Be aware that this changed slightly in MySQL 5.7. Have a look at How to change MySQL 'root' password using MySQL v5.7?

Related Question