Mysql database for Laravel app

Hi, I am newbie here.

May I know if it is possible to create and access mysql database here for my laravel application?
If yes, can someone please guide me. I am completely blank. I tried to use planetscale but it is not work! (it cannot import from normal mysql data file). Please help.

Thank you

Hi @nshahril2255

There was just a recent discussion about getting mysql setup with laravel. You would probably need to attach and mount volumes to your app.

But I am going to link to this post which goes into more details

1 Like


I actually have a rough draft of a blog article I wrote on how to get MySQL running on Fly. You may as well see it first!

The gist of it is this: You make a second app that runs MySQL, so you’ll end up with 2 apps (one app to run Laravel, another to run MySQL).

The process:

  1. Create a Fly app for MySQL
  2. Configure the app
    1. Add app secrets (to set MySQL passwords)
    2. Create and configure a volume (to persist our database data)
    3. Update fly.toml
  3. Deploy the app

Create the App

Here's what that looks like:

# Make a directory for the mysql app
mkdir my-mysql
cd my-mysql

# Run `fly launch` to create an app
fly launch

> Set an app name such as "my-mysql"
> Do not launch now if asked

Now we'll have a Fly application created named my-mysql. We haven't launched anything yet!

Configure the App

Let's create a volume straight-away. If you don't create a volume, you'll lose all of your data on any deployment (or if we move your VM to another host if there are issues).

# This assumes we're in the same directory "my-mysql"  
# alongside the fly.toml file

# Create a volume within our app "my-mysql"
fly volumes create mysqldata --region dfw --size 10

We also need to set some secrets required by the MySQL container:

# This assumes we're in the same directory "my-mysql"  
# alongside the fly.toml file

# Set secrets:
# MYSQL_PASSWORD      - password set for user $MYSQL_USER
# MYSQL_ROOT_PASSWORD - password set for user "root"
fly secrets set MYSQL_PASSWORD=password MYSQL_ROOT_PASSWORD=password

Finally, edit the fly.toml file generated to look something like this:

app = "my-mysql"
kill_signal = "SIGINT"
kill_timeout = 5


  MYSQL_DATABASE = "my_db"
  MYSQL_USER = "my_user"

  image = "mysql:8"

  cmd = ["--default-authentication-plugin", "mysql_native_password", "--datadir", "/data/mysql"]

There's a few important things to note:

  1. We deleted the [[services]] block and everything under it. We don't need it!
  2. We added the [build] section to define a Docker image. We don't need to create a Dockerfile of our own.
  3. The [env] section contains two not-so-secret environment variables that MySQL will need to initialize itself.
  4. We added the [experimental] section, which lets us set the command to run in the VM (just like Docker's CMD).
    1. For MySQL 8, you'll want to use the mysql_native_password password plugin
    2. More importantly, we set MySQL's data directory to a subdirectory of our mounted volume

:warning: Mounting a disk in Linux often results in a lost+found directory being created. However, MySQL won't initialize into a data directory unless it's completely empty. Therefore, we use a subdirectory of the mounted location: /data/mysql.

Deploy the App

Now we can deploy the application!

But wait, there's one more thing. MySQL 8+ has higher baseline resource demands than MySQL 5.7.

If you're using MySQL 8, it's best to add some additional RAM to the VM:

# Give the vm 2GB of ram
fly scale memory 2048

And then we can deploy it:

fly deploy

You should now have an app running MySQL running!

Please let me know if you run into any issues!

1 Like

Hello again!

I talked to some people at planetscale, so before you go off and make a MySQL app, if you wan to get planetscale a try again, you can use these docs to guide you on the correct mysqldump command to use:

(Planetscale uses Vitess behind the scenes so these docs relate to them as well).

The mysqldump command to use that works for planetscale would end up being something like this:

# Finish this command off with stuff specific to your database:
# hostname, user, password, database name
mysqldump --lock-tables=off --set-gtid-purged=OFF --no-tablespaces ...

You may also want to try this tool instead: GitHub - aquarapid/go-mydumper: A multi-threaded MySQL backup and restore tool, faster than mysqldump

Lastly, if your database is publicly accessible, you can use this feature from planetscale: Database Imports - Documentation - PlanetScale

This error may indicate that the docker daemon is not running.
=> in have installed docker at my pc. No more docker error above but the “Failed due to unhealthy allocations - no stab
le job version to auto revert to and deploying…” still exists

Now already start charging me $0.01 for something that is not work for me at all! Hope they will not force me to buy usd28 credit to pay for this charge. I am leaving this hell place for place that is more easy to use than this place.

Sorry, you seem to be “lucky” today and hit a few weird things.

One fun thing you can try is to add the flag --remote-only to the flyctl launch and/or flyctl deploy commands - that uses a Docker builder within Fly, instead of attempting to use the Docker you have installed locally.

Hi @nshahril2255 sorry that you ran into issues getting your app running on I will be happy to refund the charge for you.