MySQL allows you to connect without a password, although a password is set

I am installing a MySQL server (actually a Percona server, but it does not matter) and I am setting a password for the root user. At the end, I got the following:

mysql> select host, user, password from user; +-----------+------------------+-------------------------------------------+ | host | user | password | +-----------+------------------+-------------------------------------------+ | localhost | root | *huge string here, no kidding | | localhost | debian-sys-maint | *another huge string here | +-----------+------------------+-------------------------------------------+ 2 rows in set (0.00 sec) 

I thought this should not allow the root user to connect without a password. However, if I go to the command line, I can connect to mysql -u root or just mysql . If I do mysql -u root -p and press enter for password, then I get ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO).

Can someone explain to me how to make sure that the user can only connect to the password?

Edit: if necessary, I set the password using SET PASSWORD FOR 'root'@'localhost' = PASSWORD('somethinghere');

Edit: the output of show grants , it indicates that I used a password to log in, but I did not.

 mysql> show grants; +----------------------------------------------------------------------------------------------------------------------------------------+ | Grants for root@localhost | +----------------------------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*huge string here, no kidding' WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +----------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) 
+6
source share
1 answer

Facepalm. It turned out that there is .my.cnf on / root with a username and password, and therefore when using the root account (this is what I used) it was possible to log in only with mysql . It was created according to the recipe of the chef (percona was established through the chef), and I did not know about it.

The hint was to see the result of show grants . Despite the fact that I did not enter the password, he still said that I entered one, so it must be somewhere here!

+10
source

All Articles