您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

如何将csv文件导入到MySQL

2025/6/6 10:52:57发布16次查看
如何将csv文件导入到mysql?
将csv文件导入到mysql
首先登录mysql:
mysql -u root -p123456
创建数据表,保证字段和csv文件中的列一致
mysql> show databases;mysql> use test;mysql> show tables;mysql> create table mytable( -> id int not null auto_increment, -> qtime datetime not null, -> tprice float not null, -> primary key ( id ) -> )engine=innodb default charset=utf8;
查看安全路径,也就是要将上传文件放到安全路径下,才能成功上传
mysql> show variables like '%secure%';+--------------------------+-----------------------+| variable_name | value |+--------------------------+-----------------------+| require_secure_transport | off || secure_auth | on || secure_file_priv | /var/lib/mysql-files/ |+--------------------------+-----------------------+
在终端中复制文件到安全路径
sudo cp /home/hadoop/文档/文件.csv /var/lib/mysql-files
然后在到mysql下执行
mysql> load data infile '/var/lib/mysql-files/文件.csv' into table mytable fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\n';
导出文件类似
mysql> select * from `table` load data infile '/文档/test.csv' fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\n';
更多相关技术文章,请访问!
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product