How to Export and Import MySQL via Command Line - One of the important components in making a website is a database. The database serves to store data stored on the website. For example, user data, transaction data, sales data, posted article data, customer data and so on. There are various types of databases, one of which is MySQL. Quoted from DB Engines , MySQL was ranked second after Oracle. There are various ways to export and import MySQL databases, namely through phpMyAdmin and via the command line. Please read How to Import MySQL through phpMyAdmin and How to Export MySQL through phpMyAdmin . Now in this guide, we will explain how to export and import MySQL via the command line.
Before following how to export and import MySQL, you must know the following things,
1. To export and import MySQL via the command line, you must be able to access the server via SSH. Make sure you know how to access the server via SSH via Terminal and PuTTy. If you don't know, please read How to Access SSH . Oh yes, to access SSH, make sure you have at least a Super Hosting Package .
2. Make sure you have created a MySQL database account via cPanel Hosting. If not, please read How to Create a MySQL Database on Hosting
3. Make sure you know the MySQL user and password.
How to Export MySQL
Now it's time to export MySQL on Hosting via the command line / console. Please access the server via SSH via terminal or PuTTY. You can export MySQL with the output in the form of a .sql file. The commands are:
mysqldump -u NAMAUSER -p NAMADATABASE > dbexport.sql
-u: MySQL database username name
-p: use password
dbexport.sql: database file successfully exported
Write the database password then wait a moment until the export process is complete.
Please type ls in the terminal and the dbexport.sql file will appear. So that's the MySQL database that has been exported.
Note: dbexport.sql can be replaced with the database name to be exported
How to Import MySQL
So that the database can be processed again, then you need to import the PostgreSQL database. Import database means entering a database that has been exported into the database. As for how to import MySQL, namely,
mysql -u NAMAUSER -p NAMADATABASE < dbexport.sql
Write down the database password then wait a moment until the import process is complete.
-u: username from MySQL database
-p: use password
dbexport.sql: file successfully exported
The easy way:
Look at command> (on MySQL export) and command <(on import MySQL). These commands are symbols of Unix instructions.
> is STDOUT while <is STDIN.
If you want to export MySQL, please write> before the export file (dbexport.sql)
If you want to import MySQL, please write <before the export file (dbexport.sql)
How to export and import MySQL on Hosting via the command line is very easy, you know. The important thing is you have to know what the database name is, the database username name and the database password. For those who are accustomed to using the command line, maybe this guide can be tried. But for beginners, we recommend exporting and importing MySQL via phpMyAdmin only. Because it is easier and GUI based. So you just select and click the button in phpMyAdmin. If you have any questions, don't hesitate to contact the KincaiHosting Support Team!
Also Read: How to Export and Import PostgreSQL