I ran MariaDB as Docker - expose port 3306 to localhost:3307
Connect Database via localhost:3307
$ mysql -u tvgift -P 3307 -h localhost -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)
Connect Database via 172.18.0.2:3306 (IP I got from $ docker inspect <docker ID>
$ mysql -u tvgift -P 3306 -h 172.18.0.2 -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tvgift |
+--------------------+
2 rows in set (0.00 sec)
I tried another client (Using mycli) with both IP, result is same.
$ mycli mysql://tvgift:tvgift#localhost:3307/tvgift
mariadb tvgift#localhost:tvgift> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tvgift |
+--------------------+
2 rows in set
Time: 0.013s
$ mycli mysql://tvgift:tvgift#172.18.0.2:3306/tvgift
mariadb tvgift#172.18.0.2:tvgift> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tvgift |
+--------------------+
2 rows in set
Time: 0.013s
So, only mysql client have differ between two IP of one container service, can you tell me why?
localhost != any IP address. That is,
GRANT ... TO tvgift#'%' ...
does not include
GRANT ... TO tvgift#'localhost' ...
If you want to connect both via localhost and via an IP address or hostname, you must provide two GRANTs with the same permissions (such as ON tvgift.*).
Related
Stupid question maybe but for some reasons, i am unable to see my RDS mysql db instance after connecting via mysql from my ec2 instance. The EC2 and the RDS security groups have the 3306 port open between them, no issues. The database is already created as i can see it on the RDS console.
mysql -h RDS endpoint -P 3306 -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| innodb |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
Regards,
Ochen
Dears ,
I have two Virtual machines App1 & db ...
I installed Mysql in db machine , and I am trying on App1 machine to build EAR for springboot-demo-app following steps in this link (https://github.com/Mhussein27/springboot-demo-app)
But I am stuck in the step (mvn package) on app1 machine after exporting Mysql Configuration like the below , I am facing Unknown database error :
export APP_DATABASE_USER=testuser
export APP_DATABASE_PASSWORD=XXX
export APP_DATABASE_URL='jdbc:mysql://db:3306/testdb'
admin#app1:~/springboot-demo-app$ mvn package
Error:
Unable to obtain database connection
------------------------------------
SQL State : 42000
Error Code : 1049
Message : Unknown database 'testdb'
on db machine I can see the testuser and the testdb schema and privileges are fine !
mysql> SELECT User,Host FROM mysql.user;
+---------------+-----------+
| User | Host |
+---------------+-----------+
| testuser | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
mysql> SHOW GRANTS FOR 'testuser'#'%';
+------------------------------------------------------+
| Grants for testuser#% |
+------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'testuser'#'%' |
| GRANT ALL PRIVILEGES ON `testdb`.* TO 'testuser'#'%' |
+------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show tables;
+-----------------------+
| Tables_in_testdb |
+-----------------------+
| flyway_schema_history |
+-----------------------+
1 row in set (0.00 sec)
Please let me know what is wrong !!
I use mysql -u root -p to login to mysql. Command show databases only shows information_schema database, and current_user is not root
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
2 rows in set (0.00 sec)
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| #localhost |
+----------------+
1 row in set (0.00 sec)
You have no other databases - try to create one.
The current user is probably the anonymous user - by default MySQL ships with the following users, all having empty password (https://dev.mysql.com/doc/refman/5.5/en/default-privileges.html)
I have the following DBs visible in phpmyadmin:
but when I type the command show databases; it doesn't show all of them:
sudo mysql -u root
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| phpmyadmin |
+--------------------+
4 rows in set (0.00 sec)
Why is this happening?
When you type SHOW DATABASES it only shows you the databases the current user has access to.
I have two databases in mysql:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| app |
| app_dev |
+--------------------+
I have two play framework servers running, one using app and one using app_dev. The server connecting to app is local to the machine running mysql. The server connecting to app_dev is remote. I think I've setup the permissions correctly:
mysql> show grants for 'app_dev';
+------------------------------------------------------------------+
| Grants for app_dev#% |
+------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'app_dev'#'%' IDENTIFIED BY PASSWORD 'pwd' |
| GRANT ALL PRIVILEGES ON `app_dev`.* TO 'app_dev'#'%' |
+------------------------------------------------------------------+
mysql> show grants for 'app'#'localhost';
+----------------------------------------------------------------------+
| Grants for app#localhost |
+----------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'app'#'localhost' IDENTIFIED BY PASSWORD 'pwd' |
| GRANT ALL PRIVILEGES ON `app`.* TO 'app'#'localhost' |
+----------------------------------------------------------------------+
Yet for some reason, when I try to start play on my development machine, I get the response: MySQLSyntaxErrorException: SELECT command denied to user 'app_dev'#'2.ipn.ipn.ipn' for table 'play_evolutions'.
Is it possible I've set up the permissions incorrectly? The only thing that's different here is the need for the % sign as this is a remote connection!