Mysql not listing all Databases for root user - mysql

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
And now host is localhost. what should i do to get my database back.

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.

Related

Access denied for user "gestioip'#'localhost' (using password: YES)

I get this error installing gestioip. It connects to the DB as root, it creates a db (gestioip db) then it creates an user (the users: gestioip) but this user can't access the DB. (all this via browser on remote machine)
I've tried like similar posts state the following:
GRANT ALL PRIVILEGES ON dbname.* TO 'gestioip'#'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
With no effect giving the error present on the topic.
If I login the in console with:
mysql -u gestioip -p password
it works.
Needless to say that I've followed all the tutorials/installation manuals of the application.
The access to the DB is following:
gestioip#localhost
gestioip#127.0.0.1
gestioip#localhost.localdomain
Also first line in /etc/hosts:
127.0.0.1 localhost
EDIT:
I installed a ubuntu with GUI and I'm doing the install from the LOCAL browser so no remote problems should arise.
Try one of these to grant access to that user on the db u specified.
GRANT ALL PRIVILEGES ON dbname.* TO gestioip#localhost IDENTIFIED BY 'password'
GRANT ALL PRIVILEGES ON dbname.* TO 'gestioip'#'localhost' IDENTIFIED BY 'password'
U can look at this here
Or check in MySQL references guide.
Instead of localhost use 127.0.0.1
In mysql they are not the same. I imagine your connecting on 127.0.0.1 but permissions are for localhost. That is why the command works. Don't mix and match them

Mariadb host works on “localhost” but not IP alternative - 127.0.0.1

I am trying to connect to my database through an ash tunnel using sequel pro but it is not working and forces me to use 127.0.0.1 when entering "localhost" which leads to the problem where if I run on the command line:
mysql --host "localhost"
It works
If I run:
mysql --host "127.0.0.1"
I get the access denied error:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
What is going on?
I have tried:
update user set host='%' where host='localhost'
but this does not work.
Many SQL servers have two or more different user entries for every user that might come in via either localhost or remote. (127.0.0.1 counts as remote).
For example, for the root user, you might have these three user entries.
CREATE USER 'root'#'localhost' IDENTIFIED BY REDACTED;
CREATE USER 'root'#'127.0.0.1' IDENTIFIED BY REDACTED;
CREATE USER 'root'#'%.example.com' IDENTIFIED BY REDACTED;
There's nothing much special about the name root except that it has been granted a lot of privileges when your MySQL was installed. You need to grant the same privileges to the other versions of root#whatever you create.
I created a new user:
CREATE USER 'non-root'#'localhost' IDENTIFIED BY '123';
and then granted them all the same privileges:
GRANT ALL PRIVILEGES ON * . * TO 'non-root'#'localhost';
and then deleted root and renamed non-root to root
and now it finally works.

Can't access MySQL on LAN server

MySql is installed on a Ubuntu server.
I am running Windows 8.
Logging in through Putty. I can log in to database with both root and webadmin user accounts.
I can also log in through my browser, using <server ip address>/phpmyadmin
My problem is when I try to use command line to log in. I am trying that approach because I am developing a webpage to access the database on that server. It fails to connect, so I thought if command line works, the webpage will also work.
commandline:
mysql -u webadmin -p
or
mysql -u root -p
error 1045 (28000): access denied for user 'webadmin'#'localhost'
(using password: yes)
I added an iptables entry to allow mysql and that didn't work.
Also, the firewall on server is inactive.
You need to grant access to the database. You can read the documentation here: https://dev.mysql.com/doc/refman/5.1/en/grant.html
You can run the following (but be careful as it will leave your DB open)
GRANT ALL ON *.* TO 'root'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
That will allow root to connect from any IP and do any operations to the DB. If that still doesn't work, you might also need to run the following before the 2 lines above
CREATE USER 'root'#'%' IDENTIFIED BY PASSWORD '[your password]';

Granting localhost privileges or creating another user with them

I connected to MySql by this command:
$ mysql -h localhost
mysql> CREATE USER 'alex1'#localhost IDENTIFIED BY 'password$';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
And now I can't anything (create a new user with CRUD privileges, for instance) because localhost doesn't have enough privileges. I can't connect to MySql with any other credentials because I don't remember them. How do I grant localhost privileges to do that or create another user or a schema?
The problem is the user you are logged in as is the default user that will be used to access MySQL. This user does not have access to create other users.
Its not about 'localhost'.
If you know the username of an account that has grant privileges, specify it manually at the prompt:
$ mysql -u root -p -h localhost
Now it will ask you for the password for the root account for MySQL. This is normally the main "superuser" account that has all permissions.
If you don't know the root credentials and you don't have another user that has these permissions, then you need to reset the root password. Follow the steps in the manual for your operating system.

Access denied for user 'user'#'host' (using password: YES)

I have a created user in my MySQL database:
CREATE USER 'user'#'host' IDENTIFIED BY 'password';
I have granted that user full privileges:
GRANT ALL ON *.* to 'user'#'host';
Echoing the grant:
GRANT ALL PRIVILEGES ON *.* TO 'user'#'host' IDENTIFIED BY PASSWORD '*03FFC888F82E921D8CA360925A8F443CF326DE89'
I can connect from MySQL workbench using this login credential w/o any issues and execute queries. And it's running on the same machine the web application is running on. MySQL instance is running on another computer in the same local network.
However, when I try to use the same credentials from my web application running in Tomcat7 under Eclipse I receive the error. Please advise.
Note: As of last night, the web application was able to connect just fine. With nothing changing (that I am aware of - I am only one working on this), this morning I could not connect.
RESOLVED:
I added the user with grants using the IP address for the host for the local machine.
I am not sure what changed on the server, but now I am able to connect again.
Would someone possibly be able to explain this change, and with it why I am now required to use the IP address when previously the local host name was sufficient?
Make sure you are using the appropriate hostname, and you're accessing from that host, the user can't connect from another host.
To give permission you must put the password unencrypted.
Example
GRANT ALL PRIVILEGES ON test. * TO 'root' # 'localhost'
IDENTIFIED BY 'goodsecret';
Also must be the same password when you create the user.
Here How adding users to MySQL
Note: For more information on GRANT here is the documentation.
Hope this helps