MySQL: Advanced MySQL operations

How to configure, optimise, export, or import MySQL data

👋 Welcome to the Stackhero documentation!

Stackhero offers a fully managed MySQL cloud service that streamlines deployment and management for your production workloads:

  • Unlimited connections and data transfers.
  • Integrated phpMyAdmin web interface for simplified database management.
  • Effortless updates with one-click upgrades.
  • Consistent performance and enhanced security on a private, dedicated infrastructure.

With Stackhero, you have a reliable MySQL database ready within minutes. Reduce the time spent on installation and maintenance, and focus on developing your applications. Try MySQL cloud hosting on Stackhero today.

At Stackhero, there is no hard-coded limit on the number of simultaneous connections your MySQL server can accept. You have the flexibility to adjust this parameter directly from your Stackhero dashboard to suit your application's requirements.

While it may be tempting to set this value as high as possible, it is advisable to choose a limit that is appropriate for your usage. Each open connection consumes server memory (RAM), so setting it too high can place unnecessary strain on your instance and potentially make your database unstable.

If your database uses the InnoDB storage engine, you can enable the "InnoDB Optimisations" option in the Stackhero dashboard to enhance performance.

Similarly, if your database runs on the MyISAM storage engine, enabling the "MyISAM Optimisations" option can also deliver performance gains.

If you are unsure which storage engine your database uses or which optimisation option to select, it is generally recommended to enable these options by default. You can always adjust them later based on your workload or resource usage.

MySQL command-line tools such as mysql and mysqldump are very practical for importing or exporting data.

A straightforward way to access these tools is to use them within a Docker container. This approach keeps your local environment clean and avoids any manual installation.

To get started with Docker, you can launch a MySQL container by running:

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

Replace <MYSQL_VERSION> with the version you require. For example, if you are using MySQL 8.0.36-0 on Stackhero, specify 8.0.36 (without the -0 at the end).

Once the container is running, you can test the connection with the following command:

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

Here, your current directory is mounted inside the container at /mnt (thanks to the $(pwd):/mnt argument). This setup makes it easy to transfer files between your computer and the container. For example, to back up a database to your machine, you can use:

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

To create a backup (or "dump") of your database, you can use the mysqldump tool directly from your computer. (Refer to the previous section if you prefer to use it within Docker.)

To export a database from your Stackhero instance to your computer, run:

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 actual instance details. After running the command, you will be prompted for the root password. The mysqldump tool will then save your database tables in a file named <DATABASE>.sql.

To import a database from your computer into your Stackhero instance, use the following command:

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

Remember to replace yourDump.sql with the actual filename of the SQL file you wish to import.