How to set up Grafana to use MySQL database rather than the default sqlite

Hello

I am trying to use MySQL database instead of default sqlite database for grafana. I am using AWS RDS service to create MySQL database and I have hosted my grafana on ECS.
I have given name to database is database-1.

I have followed the steps to make changes in grafana.ini file. where I have given database name and password and also provided endpoint for database.

While I am trying to run the grafana service on ecs I am getting following error message.

logger=migrator t=2023-03-29T07:07:10.83376018Z level=error msg=“alert migration failure: could not get migration log” error=“failed to check table existence: Error 1049: Unknown database ‘database-1’”

hi @schachre1998 :wave:

try:

 "name": "MySQL",
 "type": "mysql",

also can you share the URL to the online instructions you followed?

1 Like

this link: Configure Grafana | Grafana documentation

So you are saying I should give my databse name as MySQL ?

1 Like

You just need to create mysql database and user for Grafana, then update Grafana’s config file.

# Either "mysql", "postgres" or "sqlite3", it's your choice
type = mysql
host = mysql-host-where-my-db-is:3306
name = db_name
user = db_username
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = MY-INSANE-STRONG-PASS

# For "postgres", use either "disable", "require" or "verify-full"
# For "mysql", use either "true", "false", or "skip-verify".
ssl_mode = disable

# Max idle conn setting default is 2
max_idle_conn = 2

Regards.

I tried with that but when I am trying to run ecs service it is giving following error.

logger=migrator t=2023-03-29T07:07:10.83376018Z level=error msg=“alert migration failure: could not get migration log” error=“failed to check table existence: Error 1049: Unknown database ‘database-1’”

I am using ENDPOINT as hostname

Hi.

If that’s a clean new installation you should not see migration warnings and errors like this.
Also Error 1049: Unknown database ‘database-1’” means the database probably don’t exist in the mysql server.

Check the mysql server DB. If you’re making a clean installation make sure the database have no tables.
Make sure the database name is the same as the one in the config. Note I wouldn’t use - in the database name.

Try creating a new one: grafana_db
Create user/pass with permissios to that database.
Update grafana config and restart the service.

Try connecting to the mysql server via ssh console from Grafana host.

Please show us (copy and paste) the relevant section of the config file where
you specify the DB details (obscure the password) and show us the command you
are running which produces the error.

Antony.