Posts Tagged MySQL

Export/Import CSV files with MySQL – No external tool required

Loading data from and to CSV or other TAB DELIMITED or similar file format is essential in day to day operation. With MySQL it is easy to load data into table using files and exporting data into CSV files is quite easy. No need to use any external tool it can be done right there from the query tool/command prompt, no specific GUI tool required.

Let's see how?

Exporting data as CSV file directly using simple MySQL Query

Simply add INTO OUTFILE [FILE_PATH] in your query and you are done. Here is a simple example:

SELECT * FROM [TABLE]
INTO OUTFILE 'X:/[FILE]'

Above statement uses default options for file export of result set of a query, but it is simple to override them. By default file will be TAB DELIMITED file. We can always override as showed in example below:

SELECT * FROM  [TABLE] INTO OUTFILE 'X:/[FILE]'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'

OR

SELECT * INTO OUTFILE 'X:/[FILE]'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM  [TABLE]

The beauty is it don't really matter where you place FROM TABLE clause, any of the style would work from above example. Don't forget that we can use all our complex join or where conditions which we really use with SELECT. Read the rest of this entry »

Tags:

backup/restore MySQL db using MYSQLDUMP (quick reference)

Whether you are using MySQL with MyISAM or InnoDB or other database engine it is possible to backup/restore database using MYSQLDUMP utility. Though if you have all tables in MyISAM format MYSQLHOTCOPY is faster option but in any case MYSQLDUMP is a handly tool if you have got a mix set of tables.

Commands are very quick simple and easy to execute and can be made automated by a PHP or other script/tool.

How to backup using mysqldump?:

Before you use any of commands you have to move to mysql/bin directory of your MySQL installation and MySQL server should be up and running.

To backup all MySQL database on a server:

mysqldump --user=[USER] --password=[PASSWORD] -A > C:/BACKUP_PATH/BACKUP_TIMESTAMP.SQL

To backup specific MySQL database on a server:

mysqldump --user=[USER] --password=[PASSWORD] [DATABASE] > C:/BACKUP_PATH/BACKUP_TIMESTAMP.SQL

To backup certain tables in a MySQL database: Read the rest of this entry »

Tags:

HeidiSQL 4.0 RC1 released

I am not sure how many MySQL developers are using HeidiSQL for development but I am sure those who are using it will be fan of some of it's features.!

I have been using HeidiSQL tool for my php/mySQL development for a while now. (more than a year and half..!). Before few months I have upgraded to newer version of HeidiSQL which is 4.1 RC1. It has got quite new and exciting features, looks and skins are improved. Read the rest of this entry »

Tags: , ,

MySQL 5.1 General Availability announced

MySQL 5.1 GA

MySQL 5.1 general availability is announced and it is available to be used for production use.

MySQL 5.1 brings many new enhancements in the bag for world's most popular open source database. which includes Partitioning, Row based Replication, new Plugin Infrastructure and there are many more including general enhancements.

There is a long list of new enhancements which you can go through in What's New section here.

Download it here if you are ready to put it in production or want to play with it in your development enviornment.

Tags: