Documentation Home
MySQL 5.6 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 31.4Mb
PDF (A4) - 31.4Mb
PDF (RPM) - 29.7Mb
HTML Download (TGZ) - 7.4Mb
HTML Download (Zip) - 7.4Mb
HTML Download (RPM) - 6.3Mb
Man Pages (TGZ) - 177.7Kb
Man Pages (Zip) - 288.0Kb
Info (Gzip) - 3.0Mb
Info (Zip) - 3.0Mb
Excerpts from this Manual

MySQL 5.6 Reference Manual  /  Alternative Storage Engines  /  The CSV Storage Engine

15.4 The CSV Storage Engine

The CSV storage engine stores data in text files using comma-separated values format.

The CSV storage engine is always compiled into the MySQL server.

To examine the source for the CSV engine, look in the storage/csv directory of a MySQL source distribution.

When you create a CSV table, the server creates a table format file in the database directory. The file begins with the table name and has an .frm extension. The storage engine also creates plain text data file having a name that begins with the table name and has a .CSV extension. When you store data into the table, the storage engine saves it into the data file in comma-separated values format.

       ENGINE = CSV;
Query OK, 0 rows affected (0.06 sec)

mysql> INSERT INTO test VALUES(1,'record one'),(2,'record two');
Query OK, 2 rows affected (0.05 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM test;
| i | c          |
| 1 | record one |
| 2 | record two |
2 rows in set (0.00 sec)

Creating a CSV table also creates a corresponding metafile that stores the state of the table and the number of rows that exist in the table. The name of this file is the same as the name of the table with the extension CSM.

If you examine the test.CSV file in the database directory created by executing the preceding statements, its contents should look like this:

"1","record one"
"2","record two"

This format can be read, and even written, by spreadsheet applications such as Microsoft Excel or StarOffice Calc.

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
  Posted by Mathias Brem Garcia on July 23, 2014
Yeah Clewett!

I make this! On my case, i needed read MySQL Error log in database, because i needed make a plugin for check errors on MySQL Error Log, but my plugins access database and don't accessed file system. So, i make this:

mysql> create table mysql.error_log(msg text not null) engine=CSV;

shell> rm -f /var/lib/mysql/mysql/error_log.CSV
shell> ln -s /var/log/mysqld.log /var/lib/mysql/mysql/error_log.CSV

So, now i read the MySQL Error Log with querys, look this:

mysql> select count(*) as ERROR from mysql.error_log where msg like '%erro%';

If the query return ERROR more then 1, alert CRITICAL.

It's an idea for another cases or to monitoring like my case