Skip to content

Instantly share code, notes, and snippets.

@alphaolomi
Created September 20, 2019 07:39
Show Gist options
  • Save alphaolomi/21b7be7070f6ba5f91648b785a25cf25 to your computer and use it in GitHub Desktop.
Save alphaolomi/21b7be7070f6ba5f91648b785a25cf25 to your computer and use it in GitHub Desktop.
Mysql Quick Commands

Mysql Quick Commands

Using Command-Line Tools

MySQL and MariaDB include two command-line tools that you can use to quickly backup and restore databases. The mysqldump tool is used to export the contents of a database to a text file, while the mysql client can be used to import data from a text file into a MySQL/MariaDB database.

To backup a MySQL/MariaDB database from the command line, follow these steps:

  1. Launch a new Windows command shell using the "Shell" button in the XAMPP control panel.

  2. Use the command below to export the contents of the selected database. In this example, we’re backing up the WordPress database, which is named bitnami_wordpress, to a file named bitnami_wordpress.sql. This text file is your backup, so store it safely!

mysqldump --user=root --password="" bitnami_wordpress > bitnami_wordpress.sql

fgsfdgs

At a later point, you may wish to restore the database. To restore the data to a fresh MySQL/MariaDB database from the command line, follow these steps:

  1. Launch a new Windows command shell using the "Shell" button in the XAMPP control panel.

  2. Use the mysql client to create a new, empty database to hold your data. In this example, the new database is named myblog.

mysql --user=root --password="" -e "CREATE DATABASE ticket"

Remember to use the correct database access credentials in the command. On a fresh XAMPP installation without any changes, you can usually log in as root with a blank password.

  1. Use the mysql client to import the contents of the backup file into the new database.
mysql --user=root --password="" --database=myblog < bitnami_wordpress.sql

The command-line client will now import the data from the backup file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment