MySQL: Using MySQL command-line tools (mysql, mysqldump, etc.)
This documentation is part of the Advanced usage guide. You can view the complete guide here: How to configure, optimise, export, or import MySQL data.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use MySQL cloud solution that provides a host of benefits, including:
- Unlimited connections and transfers.
- phpMyAdmin web UI included.
- Effortless updates with just a click.
- Optimal performance and robust security powered by a private and dedicated VM.
Save time and simplify your life: it only takes 5 minutes to try Stackhero's MySQL cloud hosting solution!
MySQL command-line tools such as mysql and mysqldump are very convenient 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.
If Docker is not part of your workflow, there is no problem at all. You may want to explore Code-Hero on Stackhero. This browser-based development platform allows you to work directly online, with no need to install anything locally. You can find out more and try it out in just a few minutes by visiting Code-Hero on Stackhero.
To get started with Docker, launch a MySQL container with the following command:
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 MySQL8.0.36-0on Stackhero, specify8.0.36(without the-0at the end).
Once the container is running, you can test the connection with this command:
mysql -u root -p -h <XXXXXX>.stackhero-network.com -P <PORT>
Your current directory is mounted to /mnt inside the container (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, use:
mysqldump -u root -p -h <XXXXXX>.stackhero-network.com -P <PORT> <DATABASE> > /mnt/<DATABASE>.sql