文本多列以,分隔,导入到指定字段:
load data local infile "file.txt" into table db.table FIELDS TERMINATED BY ',' (name,address);
load data local infile "file.txt" into table db.table (name,address) FIELDS TERMINATED BY ',';
update db.table SET aaa = 'test';
也可使用PHP以数组的方式逐行插入,自定义方便。
<?php
$hostname="localhost";
$username="root";
$password="passwd";
$dbname="dbname";
mysql_connect($hostname,$username,$password);
mysql_select_db("$dbname");
$mydate=file("/root/m.txt");
$n=count($mydate);
for($i=0;$i<$n;$i++){
$date=explode(",",$mydate[$i]);
$str="insert into table (name,address) values ('$date[0]','$date[1]')";
mysql_query($str);
}
mysql_close();
echo "ok!";
?>