iMarket Digital Properties

0 %
iMarket Digital Properties Ltd
Design · Develop · Monetize · Support
  • Location:
    United Kingdom
  • City:
    London
  • Service Area:
    Global
Business Systems
Business Services
24/7 Support
Websites
Web Applications
E-commerce Solutions
Digital Platforms
Products & Services
Public & Private Networks

How To Export A MySQL Database Using The Command Prompt

January 4, 2018

https://stackoverflow.com/questions/3031412/how-to-export-a-mysql-database-using-command-prompt

https://stackoverflow.com/questions/17666249/how-to-import-an-sql-file-using-the-command-line-in-mysql

1. Easiest Way

For Export:

$ mysqldump -u [username] -p [password] [dbname] > filename.sql

To Import:

$ mysql -u username -p database_name < file.sql

Note: It is better to use the full path of the SQL file ‘file.sql’


And if you wish to zip it at the same time:

To Export:

mysqldump -u [username] -p [password] [db] | gzip > filename.sql.gz

To Import:

$ gunzip filename.sql.gz | mysql -u [user] -p [password] [database]

2. Other Ways

For Export:

$ mysqldump --databases --user=root --password your_db_name > export_into_db.sql

The generated file will be available in the same directory where you had ran this command.


To use gzip (or just add ‘.gz’ to the end of the command above):

For Export:

$ mysqldump -u [user] -p [db_name] | gzip > [filename_to_compress.sql.gz]

For Import:

gunzip < [compressed_filename.sql.gz]  | mysql -u [user] -p[password] [databasename]

Note: There is no space between the keyword ‘-p’ and your password.

Posted in BlogTags:
Write a comment