About CSV
Contents
Lo Storage Engine può leggere e scrivere nei file registrati nel formato CSV (comma-separated-values).
Lo Storage Engine CSV e il logging sulle tabelle
Lo Storage Engine CSV è quello utilizzato per default per il logging delle query SQL nelle tabelle.
mysqld --log-output=table
Lo Storage Engine CSV e NOT NULL
Lo Storage Engine CSV non supporta le colonne con valori NULL e se si cerca di creare una tabella CSV con tali colonne si ottiene un errore:
MariaDB [test]> CREATE TABLE csv_test (x INT, y DATE, z CHAR(10)) ENGINE=CSV; ERROR 1178 (42000): The storage engine for the table doesn't support nullable columns
Si può invece aggiungere NOT NULL
alle definizioni di ogni colonna.
CSV Storage Engine files
When you create a table using the CSV storage engine, three files are created:
<table_name>.frm
<table_name>.CSV
<table_name>.CSM
The .frm
file is the table format file.
The .CSV
file is a plain text file. Data you enter into the table is stored as plain text in comma-separated-values format.
The .CSM
file stores metadata about the table such as the state and the number of rows in the table.
Examples
MariaDB [test]> CREATE TABLE csv_test ( -> x INT NOT NULL, y DATE NOT NULL, z CHAR(10) NOT NULL -> ) ENGINE=CSV; Query OK, 0 rows affected (0.11 sec)
MariaDB [test]> INSERT INTO csv_test VALUES -> (1,CURDATE(),'one'), -> (2,CURDATE(),'two'), -> (3,CURDATE(),'three'); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0
MariaDB [test]> SELECT * FROM csv_test; +---+------------+-------+ | x | y | z | +---+------------+-------+ | 1 | 2011-11-16 | one | | 2 | 2011-11-16 | two | | 3 | 2011-11-16 | three | +---+------------+-------+ 3 rows in set (0.00 sec)
$ cat csv_test.CSV 1,"2011-11-16","one" 2,"2011-11-16","two" 3,"2011-11-16","three"