首页 > 代码库 > mysql查询结果数据导出 into fileout 和cvs/txt等相关文件导入数据库中
mysql查询结果数据导出 into fileout 和cvs/txt等相关文件导入数据库中
mysql -u用户名 -p密码
mysql> use 数据库
mysql> SELECT columnID,alias,parentID FROM `cms_column` WHERE alias LIKE ‘%家庭影院%‘ OR parentID=‘144500‘ into outfile ‘/var/lib/mysql-files/column_rb.xls‘;
如果出现如下界面:
如果出现红色框中的错误,说明你的mysql配置文件导入导出权限受限,只能通过 secure_file_priv 的路径下才能操作,这里我的路径就是 /var/lib/mysql-files/
要么修改mysql配置文件,放掉权限,或者更改路径。
没有特殊规定目录路径,这里我就不那么麻烦,直接将文件copy到/var/lib/mysql-files/路径下 再次执行上面要导出的命令,如下:
mysql> SELECT columnID,alias,parentID FROM `cms_column` WHERE alias LIKE ‘%家庭影院%‘ OR parentID=‘144500‘ into outfile ‘/var/lib/mysql-files/column_rb.xls‘;
之后会看到:
这样就成功了。
下面介绍一下将本地或登录到服务器上,进行.cvs文件导入到mysql 数据库中对应到表中,这里我是在公司服务器上进行操作,准备数据如下:
--安顺(下面7行总共是一条sql语句)
LOAD DATA INFILE ‘/var/lib/mysql-files/boss/orderinfo-anshun.tsv‘ --要导入的文件
INTO TABLE orderinfo FIELDS TERMINATED BY ‘\t‘ --根据制表符 \t 也可以是逗号 , 进行每个字段分割
OPTIONALLY ENCLOSED BY ‘"‘ lines terminated by ‘\r\n‘ --根据 \r\n 说明是一条数据 要换行,
ignore 1 lines --排除第一行
(userid, permark, keyno,subkind,pcode,serialno,payway,opCode,ordertime,yxcode,servid,fees,payfees,status,isgrppay,discount,patch,company,area); --括号内是表要导入的字段
--六盘水
LOAD DATA INFILE ‘/var/lib/mysql-files/boss/orderinfo-liupanshui.tsv‘
INTO TABLE orderinfo FIELDS TERMINATED BY ‘\t‘
OPTIONALLY ENCLOSED BY ‘"‘ lines terminated by ‘\r\n‘
ignore 1 lines
(userid, permark, keyno,subkind,pcode,serialno,payway,opCode,ordertime,yxcode,servid,fees,payfees,status,isgrppay,discount,patch,company,area);
--铜仁
LOAD DATA INFILE ‘/var/lib/mysql-files/boss/orderinfo-tongren.tsv‘
INTO TABLE orderinfo FIELDS TERMINATED BY ‘\t‘
OPTIONALLY ENCLOSED BY ‘"‘ lines terminated by ‘\r\n‘
ignore 1 lines
(userid, permark, keyno,subkind,pcode,serialno,payway,opCode,ordertime,yxcode,servid,fees,payfees,status,isgrppay,discount,patch,company,area);
--遵义
LOAD DATA INFILE ‘/var/lib/mysql-files/boss/orderinfo-zunyi.tsv‘
INTO TABLE orderinfo FIELDS TERMINATED BY ‘\t‘
OPTIONALLY ENCLOSED BY ‘"‘ lines terminated by ‘\r\n‘
ignore 1 lines
(userid, permark, keyno,subkind,pcode,serialno,payway,opCode,ordertime,yxcode,servid,fees,payfees,status,isgrppay,discount,patch,company,area);
--贵阳
LOAD DATA INFILE ‘/var/lib/mysql-files/boss/orderinfo-guiyang.tsv‘
INTO TABLE orderinfo FIELDS TERMINATED BY ‘\t‘
OPTIONALLY ENCLOSED BY ‘"‘ lines terminated by ‘\r\n‘
ignore 1 lines
(userid, permark, keyno,subkind,pcode,serialno,payway,opCode,ordertime,yxcode,servid,fees,payfees,status,isgrppay,discount,patch,company,area);
mysql查询结果数据导出 into fileout 和cvs/txt等相关文件导入数据库中