Mysql·Load文件数据到表
Load CSV格式文件
数据库连接
mysql -uprod_rai_ireport -pV_O1E6Wig5jb -h 10.164.254.70 -P 3306 -D prod_rai_ireport --default-character-set=utf8 -e "sql_yuju"
命令行中登录mysql:
mysql -u用户名 -p密码 -h 192.168.236.78 -P 3306 -D 库名 -A
load data local infile '/hld/tabletxt.csv' into table table_name character set 'utf8' fields terminated by ',' enclosed by '"' lines terminated by '\n';
Windows下Load Txt格式文件到Mysql
注:数据文件分割符默认Tab键
文件格式转换
cp abc.vsv abc.txt
将文件分隔符逗号(,)转换成Tab键(linux下按ctrl+v+i)
sed -i "s/,/ /g" abc.txt
sed -i '1d' "abc.txt"
// 删除第一行
load data local infile 'C:\\Users\\RX\\Desktop\\abc.txt' into table tablename lines terminated by ' '; 插入一行
load data local infile 'C:\\Users\\RX\\Desktop\\abc.txt' into table tablename ; 插入所有数据