mysql导入csv格式文件
今天测试导入csv格式文件,虽然简单但是如果不注意还是会出现错误,而且MySQL在某些方面做的确实对新手不是很友好,记录一下:
创建一个csv格式文件:
[mysql@xxx1 ycrdb]$ more /tmp/loaddata.txt
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
创建一个引擎为csv的表:
create table ld_csv6 (id int not null default '0',name varchar(3) not null,email varchar(20) not null) engine=csv;
此时注意各个字段字符大小,如果varchar(n)中n设置的过小,咋会出现创建失败的情况,而且不告诉你为什么失败。
more /tmp/loaddata.txt > /data/mysqldata/3306/data/ycrdb/ld_csv6.CSV
此时就创建好了,确实很简单:
(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 |
如果表出现错误可以通过如下方式查询表损坏的信息,如下:
(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)
标题名称:mysql导入csv格式文件
浏览地址:http://azwzsj.com/article/ihcjdp.html
创建一个csv格式文件:
[mysql@xxx1 ycrdb]$ more /tmp/loaddata.txt
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
创建一个引擎为csv的表:
create table ld_csv6 (id int not null default '0',name varchar(3) not null,email varchar(20) not null) engine=csv;
此时注意各个字段字符大小,如果varchar(n)中n设置的过小,咋会出现创建失败的情况,而且不告诉你为什么失败。
more /tmp/loaddata.txt > /data/mysqldata/3306/data/ycrdb/ld_csv6.CSV
此时就创建好了,确实很简单:
(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 |
如果表出现错误可以通过如下方式查询表损坏的信息,如下:
(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)
标题名称:mysql导入csv格式文件
浏览地址:http://azwzsj.com/article/ihcjdp.html