How to export and import a MySQL database using the CLI

31 de octubre, 2015 @ 01:53 — 0 comentarios

In some cases you will prefer or will need to use the command line in order to export or import a MySQL database. The most common reason is when the database is really big.

In this guide we explain how to export and import a MySQL database using the command line.

Exporting a MySQL database

In order to export a MySQL database you must have access to a Unix, Linux or OS X system with MySQL client utilities.

Sppose that you have a database called myweb_db and a MySQL username called myweb_user with privileges on the database, you will have to run the following command:

mysqldump -u myweb_user -p myweb_db > myweb_db.sql

Importing a MySQL database

Suppose that you want to import the previously generated MySQL dump to a hosting account, before doing it import you will have to create a MySQL database and access the hosting account using SSH.

Once you have entered your hosting account using SSH, execute the following command:

mysql -u myweb_user -p myweb_db < myweb_db.sql

NOTE: You wull have to replace myweb_user and myweb_db with the correct values.