How to import and export MySQL database into an SQL file

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:

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:

[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.

Ma.gnolia.com experience data loss and corruption

Ma.gnolia.com experience data loss and corruption and the service is thus disrupted. I wonder if there are any backups. Seems like it just crashed and recovery is going to be hard.

Dear Ma.gnolia Community Members or Visitor,

Early on the West-coast morning of Friday, January 30th, Ma.gnolia experienced every web service’s worst nightmare: data corruption and loss. For Ma.gnolia, this means that the service is offline and members’ bookmarks are unavailable, both through the website itself and the API. As I evaluate recovery options, I can’t provide a certain timeline or prognosis as to to when or to what degree Ma.gnolia or your bookmarks will return; only that this process will take days, not hours.

I will of course keep you appraised here and in our Twitter account.

Most importantly, I apologize to all of you who have made Ma.gnolia a home for your bookmarks and community. I know that many of you rely on Ma.gnolia in your day to day work and play flow to safely host you bookmarks, keeping them available around the clock, and that this is a difficult disruption.

Sincerely,
Larry

I would be very upset if delicious is gone.

How to backup and restore in PostgreSQL

I was fairly impressed with pgAdmin III when I first used it. It seems to be simple to use for anyone who can’t write their own SQL statements. I wasn’t too good and it and each time I execute a change in the database I have a feeling the world’s going to end. But one thing the pgAdmin III doesn’t do well is backup and restore.

Using pgAdmin III for PostgreSQL

(Using pgAdmin III for PostgreSQL. A screenshot.)

0. Objective

In the end it’s best to use the command prompt (or terminal) and in this really beginner tutorial, we’ll do a backup and restore using the command line.

1. Set PATH for PostgreSQL in Windows Vista

This guide assumes you install in ‘C:Program FilesPostgreSQL8.3’, the default installation directory. Continue reading “How to backup and restore in PostgreSQL”