Some tips and tricks I’m tracking as I navigate my way through MySQL again.
Show users
mysql> SELECT User, Host FROM mysql.user;
+------------------+-----------+
| User | Host |
+------------------+-----------+
| bill | % |
| root | % |
| grafana | 10.0.0.3 |
| my2 | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
8 rows in set (0.00 sec)
mysql>
Show databases
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| exampledb |
| information_schema |
| my2 |
| mysql |
| performance_schema |
| sys |
| telemetry |
+--------------------+
7 rows in set (0.01 sec)
mysql>
Grant privileges
Note. User grafana
is only allowed to connect from host 10.0.0.3
(Docker container IP running MySQL)
mysql> GRANT ALL PRIVILEGES ON exampledb.* TO 'grafana'@'10.0.0.3';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
Confirm privileges
mysql> SHOW GRANTS FOR 'grafana'@'10.0.0.3';
+---------------------------------------------------------------+
| Grants for grafana@10.0.0.3 |
+---------------------------------------------------------------+
| GRANT USAGE ON *.* TO `grafana`@`10.0.0.3` |
| GRANT ALL PRIVILEGES ON `exampledb`.* TO `grafana`@`10.0.0.3` |
| GRANT SELECT ON `my2`.* TO `grafana`@`10.0.0.3` |
+---------------------------------------------------------------+
3 rows in set (0.00 sec)
mysql>