Archive for the ‘MySQL’ category

Importing a SQL file directly from Command Line for MySQL

October 18th, 2011

I am writing this on the train, so I’ll be relatively quick.

It’s been a while since I wrote my import sql file via command line post and thought I’d post the updated version which I now use.

It is possible to execute an SQL file without logging into the mysql client first. Previously, I used login to mysql and use the source command to execute commands from an SQL text file.

Now, I execute it all straight from bash or windows shell without having to login to the MySQL client.

To import an SQL file by passing it as if it were an arguement, you need to use the < sign. So for example, say that I wanted to import an external database from production and wanted to import it into my development environment, I can do so by doing the following:

» Read more: Importing a SQL file directly from Command Line for MySQL

MySQL Funny/Strange Characters replacing apostrophes after import

May 26th, 2009

Our client contact from a Web Design Company we develop web applications and business websites for rang us late yesterday with a problem they had encountered. They were migrating a database from one MySQL database server to another and noticed that question marks and other strange characters such as aeons or blackbox question marks are appearing everywhere.

How did this happen?
This happens because the test server’s character set (utf8) did not match the production servers client (which is set to latin1 by default) this is what does all the importing and since UTF8 Unicode has some characters that are missing or are different to latin1, they are replaced with a question mark.

» Read more: MySQL Funny/Strange Characters replacing apostrophes after import

Importing SQL dumps into MySQL through Command line

March 11th, 2008

UPDATE 2011: I’ve created another blog post on this subject which describes an easier way of importing SQL files directly from the command line with MySQL. The method on the new blog post describes how to do it in one step directly from the command line. Check it out!

Perhaps it’s because I’ve been in maintenance mode for a little bit that I’ve forgotten how to import a SQL file generated by applications like mysqldump into an existing database, but earlier today while dumping existing data from DevScripts and trying to install it on our testing server, I drew a complete blank.

So I guess this is more a note for me and anyone else who has a tendency to forget nifty little tricks like this one.

A quick way to duplicate MySQL databases is to do the following:

» Read more: Importing SQL dumps into MySQL through Command line