Quantcast
Channel: i.justrealized » windows
Viewing all articles
Browse latest Browse all 10

How to import and export MySQL database into an SQL file

$
0
0

Or Gzip for the matter. Here’s the command to run in your UNIX-based server to import or export via an SQL file, this is useful for performing backup and restoring of a MySQL database. (I wrote a similar import and export guide for PostgreSQL.) The mysqldump utility performs just that:

Exporting using mysqldump:

mysqldump -u[Username] -p[Password] [Database] > output.sql

For example, my username is ‘kahwee’, my password being ‘secret’ and database being ‘justrealized_db’, I would run the following to export my database to a SQL file:

mysqldump -ukahwee -psecret justrealized_db > output.sql

And to Gzip:

mysqldump -u[Username] -p[Password] [Database] | gzip > output.sql.gz

Importing using mysql:

To import back, we can use the mysql utility in a similar fashion, note that the > (greater than) has change to a < (lesser than).

mysql -u[Username] -p[Password] [Database] < output.sql

For example, my username is 'kahwee', my password being 'secret' and database being 'justrealized_db', I would run the following to import my database:

mysql -ukahwee -psecret justrealized_db < output.sql

And to Ungzip:

gunzip < output.sql.gz | mysql -u[Username] -p[Password] [Database]

Backing up and restoring MySQL databases in Windows

Unfortunately, you can't use gzip here. So all those commands above with gzip can't work. The rest, however, still works. However, mysqldump and mysql may not be set in your system environment variables. These are instructions on how to add them for Windows Vista:

Editing system environment variables in Windows Vista.

Click on 'Edit the system environment variables', a dialog box will pop up. Click on 'Environment Variables...', you should be greeted with the following dialog box:

Editing the path for environment variables

My path looks like this before I add anything:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem

Append your MySQL bin directory at the back of what is already there. I use XAMPP (XAMPP lite to be specific) which has its MySQL bin folder located here ';C:\xampplite\mysql\bin\', so I would be appending this:

;C:\xampplite\mysql\bin\

That's all I guess, hope it is helpful for you.


Viewing all articles
Browse latest Browse all 10

Trending Articles