Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql imports files in csv format

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report