MySQL: Using MySQL command-line tools (mysql, mysqldump, etc.)

This documentation is part of the Advanced MySQL operations guide. You can view the complete guide here: 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.

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 MySQL 8.0.36-0 on Stackhero, use 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