0

I have a mysql database running on k8s cluster inside pod. it was previously listing all the databases when i login through mysql -u root -p and then entering password. But my application was not able to connect to that database and was showing 1045, "Access denied for user 'root'@'ipaddress' (using password: YES)" there was just one host which is % and user was root

i have updated secrets as well and restart deployment but still it was showing the above error.

then i ran this command to grant all privileges to root user

GRANT ALL ON root.* TO 'root'@'localhost' IDENTIFIED BY 'password';

it creates one more host for root which is localhost. Now when i try to login with

mysql -u root -p

it is not listing my databases and just showing

enter image description here

And now host is localhost. what should i do to get my database back.

squillman
  • 13,363
  • 3
  • 41
  • 60
bigDaddy
  • 23
  • 1
  • 5

1 Answers1

1

In MySQL permissions are granted for "accounts" which consist of a user name and a host name [1]. So in terms of GRANTS:

myuser@127.0.0.1
myuser@192.168.1.1

The above are two different users. The wildcard in terms of permissions is %. However % and localhost are mutually exclusive as explained here.

So having that in mind you would need to run something close to:

CREATE USER 'root'@'%' IDENTIFIED BY 'changeme';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'root'@'%';

In order to enable connections coming from a different host. Please keep in mind that using the username root should be avoided. Instead, use a dedicated user for your needs.

HiroCereal
  • 550
  • 1
  • 11