3

When I am root, "mysql" connects without a password, even though I've set one:

# mysqladmin -u root password 'whatever'
# mysql -u root -p
Enter password: (typing the 'whatever' above)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.1.22-standard

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> Bye

but unfortunately this also happens...

# mysql -u root 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25 to server version: 4.1.22-standard

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> 

So even though I've set the password, and it IS checked when I use "-p", it is however not necessary!?!?

EDIT: It was my .my.cnf, it had the login password inside it. Removed it, all OK.

John Smith
  • 31
  • 2

3 Answers3

4

Maybe you have user credentials in your ~/.my.cnf

[client]
user=john
password=smith
Silent-Bob
  • 1,066
  • 6
  • 9
1

In my case it was that the MySQL root user was using the Socket Peer-Credential Pluggable Authentication.

From what I understand, is that if the unix user that invokes the mysql command matches the MySQL user it will allow a connection for a local socket (no remote). So passing in any password will have no effect because this type of auth does not need a password.

You can see if you have any users that use auth_socket plugin.

select Host, User, plugin from mysql.user where plugin = 'auth_socket';

I was using Ubuntu 18.04 and ran the mysql_secure_installation script.

Lunfel
  • 115
  • 6
-2
mysql> update user set plugin='' where User='root'; 
mysql> flush privileges;
Ladadadada
  • 26,337
  • 7
  • 59
  • 90
wowks
  • 1