MySQL: Advanced MySQL operations
How to configure, optimize, 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 get a reliable MySQL database ready in just a few minutes. Spend less time on setup and maintenance, and focus on developing your applications. Try MySQL cloud hosting on Stackhero today.
Configuring the maximum number of MySQL connections
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 might be tempting to set this value as high as possible, it is recommended to choose a limit that matches your actual usage. Each open connection consumes server memory (RAM), so setting it too high can put unnecessary strain on your instance and potentially make your database unstable.
Optimizing MySQL for InnoDB or MyISAM storage engines
If your database uses the InnoDB storage engine, you can enable the "InnoDB Optimizations" option in the Stackhero dashboard to improve performance.
Similarly, if your database runs on the MyISAM storage engine, enabling the "MyISAM Optimizations" option can also provide performance gains.
If you are unsure which storage engine your database uses or which optimization option to select, it is generally advisable to enable these options by default. You can always adjust them later based on your workload or resource usage.
Using MySQL command-line tools (mysql, mysqldump, etc.)
MySQL command-line tools such as mysql and mysqldump are very practical for importing or exporting data.
A simple way to access these tools is to use them within a Docker container. This approach keeps your local environment clean and avoids manual installations.
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 need. For example, if you are running MySQL8.0.36-0on Stackhero, use8.0.36(without the-0at 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
Backing up a MySQL database
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 inside Docker.)
Exporting a MySQL database to your computer
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.
Importing a MySQL database to your server
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 want to import.