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:
[code lang=”bash”]mysqldump -u[Username] -p[Password] [Database] > output.sql[/code]
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:
[code lang=”bash”]mysqldump -ukahwee -psecret justrealized_db > output.sql[/code]
And to Gzip:
[code lang=”bash”]mysqldump -u[Username] -p[Password] [Database] | gzip > output.sql.gz[/code]
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).
[code lang=”bash”]mysql -u[Username] -p[Password] [Database] < output.sql[/code]
For example, my username is ‘kahwee’, my password being ‘secret’ and database being ‘justrealized_db’, I would run the following to import my database:
[code lang=”bash”]mysql -ukahwee -psecret justrealized_db < output.sql[/code]
And to Ungzip:
[code lang=”bash”]gunzip < output.sql.gz | mysql -u[Username] -p[Password] [Database][/code]
[ad#simple]
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:
Image may be NSFW.
Clik here to view.
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:
Image may be NSFW.
Clik here to view.
My path looks like this before I add anything:
[code lang=”bash”]%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem[/code]
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:xampplitemysqlbin’, so I would be appending this:
[code lang=”bash”];C:xampplitemysqlbin[/code]
That’s all I guess, hope it is helpful for you.