Sunday, 18 December 2011

Import or Export A database in MySQL


1. Export A MySQL Database

This example shows you how to export a database. It is a good idea to export your data often as a backup.



  1. Login into your website ssh using your hostname and password:



  2. Go to mysql prompt by typeing mysql



  3. Export your mysql by below command:

    mysqldump -u username -p database_name > dbname.sql



  4. You will be prompted for a password, type in the password for the username and press Enter.

    # Must replace username, password and database_name with your MySQL username, password and database name.



File dbname.sql now holds a backup of your database on the site. Locate the dbname.sql file and download to your computer.

2. Import A MySQL Database

The file must be in .sql format. It can not be compressed in a .zip or .tar.gz file.



  1. Start by uploading the .sql file onto website ftp, basically on the root of the site.



  2. Login to SSH, navigate to the directory where your .sql file is.



  3. Next run this command:

    mysql -p -u username database_name < dbname.sql

    # The -p will prompt for your account's password.

    #: Be sure that the database exits on the server..



3 comments :

  1. Of course, what a fantastic blog and illuminating posts, I will bookmark your site.Best Regards!

    ReplyDelete
  2. Great blog! Do you have any recommendations for aspiring writers? I'm hoping to start my own website soon but I'm a little lost on everything. Would you suggest starting with a free platform like Wordpress or go for a paid option? There are so many options out there that I'm totally confused .. Any ideas? Many thanks!

    ReplyDelete
  3. First, best wishes for your up-coming blog. You can rely on the wordpress for ever. However, if your wallet allows, can go for paid wordpress themes which are very light-weight, seo-friendly. Best of Luck!

    ReplyDelete