A Simple Method for importing data to mysql.
Because ubuntu comes with mysql 5.5 by default and cannot use the advanced feature load data infile, we have written a general script to upload files.
Shell script
cat ./employee.csv | while read LINE do eval $( echo $LINE | awk -F ',' '{print "ds="$1 ";id="$2 ";name="$3}' ) echo ds=$ds id=$id name=$name mysql -uroot -p655453 test --default-character-set=utf8 -e "replace into wechat_employee values('$ds','$id','$name')"done
The most important thing to import data to Mysql is to combine three codes, that is, the client and server encoding and table encoding must be consistent, server encoding can be found in/etc/mysql to modify the configuration file. The client encoding can be set before insert, which can be ignored.
show variables like '%char%';+--------------------------+----------------------------+| Variable_name | Value |+--------------------------+----------------------------+| character_set_client | utf8 || character_set_connection | utf8 || character_set_database | utf8 || character_set_filesystem | binary || character_set_results | utf8 || character_set_server | utf8 || character_set_system | utf8 || character_sets_dir | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+
View the table encoding. If it is not utf8, modify it.
mysql> show create table wechat_employee;+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| wechat_employee | CREATE TABLE `wechat_employee` ( `ds` varchar(20) DEFAULT NULL, `femployeeid` int(20) DEFAULT NULL, `femployeename` varchar(256) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 |+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)
Next, import.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.