<p>I have a mysql database running on k8s cluster inside pod. it was previously listing all the databases when i login through <code>mysql -u root -p</code> and then entering password. But my application was not able to connect to that database and was showing <code>1045, &quot;Access denied for user 'root'@'ipaddress' (using password: YES)&quot;</code> there was just one host which is % and user was root</p>
<p>i have updated secrets as well and restart deployment but still it was showing the above error.</p>
<p>then i ran this command to grant all privileges to root user</p>
<pre><code>GRANT ALL ON root.* TO 'root'@'localhost' IDENTIFIED BY 'password';
</code></pre>
<p>it creates one more host for root which is localhost. Now when i try to login with</p>
<pre><code>mysql -u root -p
</code></pre>
<p>it is not listing my databases and just showing</p>
<p><a href="https://i.stack.imgur.com/Cj2jC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cj2jC.png" alt="enter image description here" /></a></p>
<p>And now host is localhost. what should i do to get my database back.</p>

bigDaddy
<p>In MySQL permissions are granted for &quot;accounts&quot; which consist of a user name and a host name <a href="https://dev.mysql.com/doc/refman/8.0/en/account-names.html" rel="nofollow noreferrer">[1].</a> So in terms of GRANTS:</p>
<pre><code>myuser@127.0.0.1
myuser@192.168.1.1
</code></pre>
<p>The above are two different users. The wildcard in terms of permissions is <code>%</code>. However <code>%</code> and <code>localhost</code> are mutually exclusive as explained <a href="https://stackoverflow.com/questions/10823854/using-for-host-when-creating-a-mysql-user">here</a>.</p>
<p>So having that in mind you would need to run something close to:</p>
<pre><code>CREATE USER 'root'@'%' IDENTIFIED BY 'changeme';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'root'@'%';
</code></pre>
<p>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.</p>
