neogeek23
neogeek23

Reputation: 893

Grafana selecting data from MySql always gives Command Denied Error 1142

I'm trying to use grafana with mysql. MySql is getting data from wordpres. I can connect to the MySql database with grafana but any attempt to query the database results in a permission error quoted below. Does anyone know what I'm doing wrong? I made sure to FLUSH PRIVILEGES; when creating this account.

What account is being used?

mysql> SELECT USER(),CURRENT_USER();
+-------------------+-------------------+
| USER()            | CURRENT_USER()    |
+-------------------+-------------------+
| grafana@localhost | grafana@localhost |
+-------------------+-------------------+
1 row in set (0.00 sec)

What permissions does the account have?

mysql> show grants for 'grafana'@'localhost';
+------------------------------------------------------------------------+
| Grants for grafana@localhost                                           |
+------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'grafana'@'localhost' WITH GRANT OPTION |
+------------------------------------------------------------------------+
1 row in set (0.00 sec)

Can I select from a table? (Yes)

mysql> select * from wp_users;
+----+---------------+------------------------------------+---------------+---------------------------+----------+---------------------+-----------------------------------------------+-------------+---------------+
| ID | user_login    | user_pass                          | user_nicename | user_email                | user_url | user_registered     | user_activation_key                           | user_status | display_name  |
+----+---------------+------------------------------------+---------------+---------------------------+----------+---------------------+-----------------------------------------------+-------------+---------------+
|  1 | admin         | ********************************** | admin         | [email protected]           |          | 2019-02-22 18:09:58 |                                               |           0 | something     |
+----+---------------+------------------------------------+---------------+---------------------------+----------+---------------------+-----------------------------------------------+-------------+---------------+
1 row in set (0.00 sec)

What is my mysql info?

mysql> status
--------------
mysql  Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using  EditLine wrapper

Connection id:      42787
Current database:   information_schema
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.7.25-0ubuntu0.18.04.2 (Ubuntu)
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    utf8
Client characterset:    latin1
Conn.  characterset:    latin1
UNIX socket:        /var/run/mysqld/mysqld.sock
Uptime:         43 days 2 hours 29 min 53 sec

Threads: 3  Questions: 3576291  Slow queries: 0  Opens: 1570  Flush tables: 1      Open tables: 692  Queries per second avg: 0.960
--------------

What query am a trying to run in grafana?

SELECT
  user_registered,
  user_login
FROM wp_users

I tried with with and without a trailing ; - no change.

What does grafana give back to me with this query?

Error 1142: SELECT command denied to user 'grafana'@'localhost' for table 'wp_users'

I realize that this account has too many permissions, but seeing as grafana thinks it doesn't have enough, for now I'm trying to get it to work with at least more than it needs.

Upvotes: 0

Views: 598

Answers (1)

neogeek23
neogeek23

Reputation: 893

After being stumped by this for a few hours, the notion of looking at logs was suggested to me. Since MySql doesn't have logs enabled by default, I changed the settings to enable the logs and restarted MySql. After doing this everything worked fine. It seems all I had to do was to restart the service.

The solution:

sudo service mysql restart

Upvotes: 1

Related Questions