MariaDB: Advanced MariaDB operations

How to configure, optimize, export, or import MariaDB data

👋 Welcome to the Stackhero documentation

Stackhero offers a ready-to-use MariaDB cloud solution with a range of benefits, including:

  • Unlimited connections and data transfers.
  • Built-in phpMyAdmin web interface.
  • One-click updates for simplified maintenance.
  • Optimal performance and enhanced security thanks to private, dedicated infrastructure.

Save time and make your life easier: it only takes 5 minutes to try Stackhero's MariaDB cloud hosting solution!

With Stackhero, you are not bound by a fixed limit on the number of simultaneous connections your service can support. You have the flexibility to adjust this value directly from your Stackhero dashboard.

While it might be tempting to set a very high connection limit, it is best to choose a number that reflects your actual usage. Each connection consumes memory (RAM), so setting the limit too high can exhaust your resources and potentially cause your system to crash.

If your database uses the InnoDB storage engine, you may want to enable the "InnoDB Optimizations" option in your dashboard. This can help improve performance for workloads based on InnoDB.

For databases using the MyISAM storage engine, enabling the "MyISAM Optimizations" option can also provide benefits.

If you are unsure which option is best for your setup, it is generally safe to enable both initially. As you monitor your resource usage and performance, you can later decide whether to disable one or both to save memory (RAM).

The MariaDB query cache is a useful feature that you can enable directly from the Stackhero dashboard. It is generally recommended to keep it enabled. However, if your database performs more writes than reads, or if you want to reduce memory usage, you may consider disabling it.

MariaDB command-line tools such as mysql and mysqldump are essential for tasks like importing or exporting data.

Running these tools inside a Docker container simplifies setup, especially if you want to avoid installing software directly on your computer.

To get started with Docker, you can launch a MariaDB container with the following command:

docker run -it -v $(pwd):/mnt mariadb:<MARIADB_VERSION> /bin/bash

Replace <MARIADB_VERSION> with the specific MariaDB version you need. For example, if your application uses MariaDB version 10.11.6-0 on Stackhero, you can use version 10.11.6 (just omit the -0 suffix).

Once your container is running, you can test your connection with:

mysql -u root -p -h <XXXXXX>.stackhero-network.com -P <PORT>

When you start the container, your current directory is mounted to /mnt inside it (thanks to $(pwd):/mnt). This means any file in your current directory on your computer will be accessible in /mnt inside the container. For example, to back up a MariaDB database to your machine, you can run this command inside the container to save the backup as /mnt/<DATABASE>.sql:

mysqldump -u root -p -h <XXXXXX>.stackhero-network.com -P <PORT> <DATABASE> > /mnt/<DATABASE>.sql

You can use the mysqldump CLI from your computer to back up a database. For step-by-step details, please refer to the section above.

To export a database from your Stackhero instance to your computer, use the following command:

mysqldump -u root -p -h <XXXXXX>.stackhero-network.com -P <PORT> <DATABASE> > <DATABASE>.sql

Be sure to replace <XXXXXX>.stackhero-network.com, <PORT>, and <DATABASE> with your own information. After you press Enter, mysqldump will prompt you for the root password. It will then export all tables from your database into the file <DATABASE>.sql.

To import a database from your computer to your Stackhero instance, use:

mysql -u root -p -h <XXXXXX>.stackhero-network.com -P <PORT> <DATABASE> < yourDump.sql

Simply replace yourDump.sql with the SQL file you want to import into your Stackhero instance.