MySQL app doesn't start

I was following this tutorial on how to set up a mySQL database, but for some reason the app doesn’t start whatever I do. I have run the following commands:

mkdir mysql_fly
cd mysql_fly
flyctl launch
flyctl volumes create mysqldata --size 1
flyctl secrets set MYSQL_PASSWORD=epicpassword MYSQL_ROOT_PASSWORD=epicpassword
flyctl deploy

And the fly.yml file looks like this:

app = "appname"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[mounts]
  source="mysqldata"
  destination="/data"

[env]
  MYSQL_DATABASE = "database_name"
  MYSQL_USER = "root"

[build]
  image = "mysql:8"

[experimental]
  cmd = [
    "--default-authentication-plugin", 
    "mysql_native_password", 
    "--datadir",
    "/data/mysql",
    "--performance-schema=OFF"
  ]

I am not sure what am I doing wrong here, but in the logs I just get this repeated three times before the app dies:

2023-01-19T17:00:20.800 runner[061bb749] den [info] Starting instance

2023-01-19T17:00:21.386 runner[061bb749] den [info] Configuring virtual machine

2023-01-19T17:00:21.387 runner[061bb749] den [info] Pulling container image

2023-01-19T17:00:21.802 runner[061bb749] den [info] Unpacking image

2023-01-19T17:00:21.810 runner[061bb749] den [info] Preparing kernel init

2023-01-19T17:00:21.950 runner[061bb749] den [info] Setting up volume 'mysqldata'

2023-01-19T17:00:21.953 runner[061bb749] den [info] Opening encrypted volume

2023-01-19T17:00:22.111 runner[061bb749] den [info] Configuring firecracker

2023-01-19T17:00:22.169 runner[061bb749] den [info] Starting virtual machine

2023-01-19T17:00:22.416 app[061bb749] den [info] Starting init (commit: b8364bb)...

2023-01-19T17:00:22.445 app[061bb749] den [info] Mounting /dev/vdc at /data w/ uid: 0, gid: 0 and chmod 0755

2023-01-19T17:00:22.450 app[061bb749] den [info] Preparing to run: `docker-entrypoint.sh --default-authentication-plugin mysql_native_password --datadir /data/mysql --performance-schema=OFF` as root

2023-01-19T17:00:22.472 app[061bb749] den [info] 2023/01/19 17:00:22 listening on [fdaa:1:27e7:a7b:d828:4:2d83:2]:22 (DNS: [fdaa::3]:53)

2023-01-19T17:00:22.514 app[061bb749] den [info] 2023-01-19 17:00:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.

2023-01-19T17:00:22.928 app[061bb749] den [info] 2023-01-19 17:00:22+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'

2023-01-19T17:00:22.949 app[061bb749] den [info] 2023-01-19 17:00:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.

2023-01-19T17:00:23.464 app[061bb749] den [info] Starting clean up.

2023-01-19T17:00:23.465 app[061bb749] den [info] Umounting /dev/vdc from /data

What could be causing this?

Hi @bro912 !

Can you change the MYSQL_USER to a different user other than root, redeploy and see if that fixes the issue?

1 Like

Worked like a charm, thank you. But isn’t root the default user in MySQL? The database is (obviously) empty and there are no other usernames, however changing to the user to random name actually fixed the issue. Anyways, do you also happen to know how to connect to this database using python? From another app running on fly.io on the same account, that is.

The MYSQL image used allows us to create a MYSQL user using the env variable MYSQL_USER—which we are setting in our fly.toml file.

To connect your Python Fly app to your MYSQL Fly app simply configure your Python Fly app’s MYSQL hostname to point to your MYSQL database’s fly.internal address.

More details here on the connection.

It’s not Python, but here’s a quick, sample configuration to connect a Laravel Fly App to a MYSQL Fly app

2 Likes

I have tried connecting to the database as usual with a configuration looking something like this:

configfly = {
  'user': 'user_from_yml_file',
  'password': 'epicpassword',
  'host': 'appname.internal',
  'database': 'database_name',
  'raise_on_warnings': True,
  'collation': 'utf8mb4_general_ci'
}

It seems to be connecting fine, but I get this error: Access denied for user 'user_from_yml_file'@'%' to database 'database_name'. How can this be fixed? This is the same password that I set in secrets, and the user is also the same one that I inserted into the MYSQL_USER in the yml file.

1 Like

Notice, the error, it specifically says “Access denied … to database”. This might mean you properly specified credentials for the user, but your user has no access to the database in the connection.

A good next step is to make sure the MYSQL_DATABASE in your MYSQL Fly app matches the database you are trying to connect to

Use fly ssh console to access your MySQL Fly app, then run a quick printenv command to get its variables. You should be able to see the value there of MYSQL_DATABASE

If the value is the same as your configured value above, then its possible that the error received
has got something to do with your user’s privileges

1 Like

My bad, I in one of four files I accidentally used dashes instead of underscores like a lunatic. Thank you for all your help :slight_smile:

1 Like