8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

18.4 CSV 存储引擎18.4 The CSV Storage Engine

CSV 存储引擎使用逗号分隔值格式在文本文件中存储数据。The CSV storage engine stores data in text files using comma-separated values format.

CSV 存储引擎总是被编译进 MySQL 服务器。The CSV storage engine is always compiled into the MySQL server.

要查看 CSV 引擎的源代码,请查看 MySQL 源代码发行版中的 storage/csv 目录。To examine the source for the CSV engine, look in the storage/csv directory of a MySQL source distribution.

当你创建一个 CSV 表时,服务器会创建一个纯文本数据文件,该文件的名称以表名开头,并具有 .CSV 扩展名。当你将数据存储到表中时,存储引擎会以逗号分隔值格式将其保存到数据文件中。When you create a CSV table, the server creates a 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.

mysql> CREATE TABLE test (i INT NOT NULL, c CHAR(10) NOT NULL)
    ->     ENGINE = CSV;
Query OK, 0 rows affected (0.06 sec)

mysql> INSERT INTO test
    ->     VALUES ROW(1,'record one'), ROW(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)

创建一个 CSV 表也会创建一个相应的元文件,用于存储表的状态和表中存在的行数。该文件的名称与表名相同,扩展名为 CSM。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.

如果你检查在执行前述语句后在数据库目录中创建的 test.CSV 文件,其内容应如下所示: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"

这种格式可以被电子表格应用程序(如 Microsoft Excel)读取,甚至写入。This format can be read, and even written, by spreadsheet applications such as Microsoft Excel.