CSV Storage Engine

The CSV storage engine is a special-purpose engine that allows you to store data in plain comma-separated value (CSV) files. Each table using the CSV engine is represented by a single CSV file in the data directory. This engine is primarily useful for exchanging data with applications that produce or consume CSV files.

Key Characteristics

Use Cases

Limitations

Due to its simplicity, the CSV engine is not suitable for performance-critical applications or scenarios requiring complex querying, data integrity, or concurrency control.

Creating a CSV Table

To create a table that uses the CSV storage engine, specify ENGINE=CSV in your CREATE TABLE statement:


CREATE TABLE sales_data (
    product_id INT,
    sale_date DATE,
    quantity INT,
    price DECIMAL(10, 2)
) ENGINE=CSV;
        

Data Format and Delimiters

By default, the CSV engine uses a comma (,) as the field delimiter and a newline character as the row terminator. These can be configured using table options:


CREATE TABLE customer_list (
    customer_id INT,
    name VARCHAR(100),
    email VARCHAR(100)
) ENGINE=CSV
  DEFAULT CHARACTER SET utf8mb4
  FIELD DELIMITED BY ';'
  OPTIONALLY ENCLOSED BY '"'
  ESCAPED BY '\\'
  LINES TERMINATED BY '\n';
        

Table Options:

Note on Data Types

The CSV engine does not enforce data types. All values are stored and retrieved as strings. Any interpretation or conversion of data types must be handled by the application interacting with the CSV file.

Operations and Performance

Operations on CSV tables are generally slow due to the lack of indexing and the need to parse/write text files. Inserts and updates involve appending or rewriting the entire file, which can be inefficient for large datasets.

When to Use the CSV Engine

When NOT to Use the CSV Engine