Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql imports files in csv format

Shulou Source: shulou.com Published: 2022-06-01 06:10:56 09月17日 Update

Today's test imports csv format files, although it is simple, but if you do not pay attention, there will still be errors, and mysql is really not very friendly to beginners in some ways, make a note of it:

Create a file in csv format:

[mysql@xxx1 ycrdb] $more / tmp/loaddata.txt

1recoveryabcrecoveryqq.com

1recoveryabcrecoveryqq.com

1recoveryabcrecoveryqq.com

1recoveryabcrecoveryqq.com

1recoveryabcrecoveryqq.com

1recoveryabcrecoveryqq.com

1recoveryabcrecoveryqq.com

1recoveryabcrecoveryqq.com

Create a table with the engine csv:

Create table ld_csv6 (id int not null default '0century journal name varchar (3) not null,email varchar (20) not null) engine=csv

Pay attention to the character size of each field at this time. If the n setting in varchar (n) is too small, how will the creation fail, and will not tell you why it failed.

More / tmp/loaddata.txt > / data/mysqldata/3306/data/ycrdb/ld_csv6.CSV

It's created at this point, and it's really simple:

(system@localhost) [ycrdb] > select * from ld_csv6

+-- +

| | id | name | email | |

+-- +

| | 1 | abc | abc@qq.com |

| | 1 | abc | abc@qq.com |

| | 1 | abc | abc@qq.com |

| | 1 | abc | abc@qq.com |

| | 1 | abc | abc@qq.com |

| | 1 | abc | abc@qq.com |

| | 1 | abc | abc@qq.com |

| | 1 | abc | abc@qq.com |

If there is an error in the table, you can query the information about the table corruption in the following ways, as follows:

(system@localhost) [ycrdb] > check table ld_csv5

+-+

| | Table | Op | Msg_type | Msg_text | |

+-+

| | ycrdb.ld_csv5 | check | error | Corrupt | |

+-+

1 row in set (0.02 sec)

Tags: File format error information can be passed size field character engine situation novice method aspect query table or build query test Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Linux MySQL Xiaomi