当前位置:网站首页>Mysqlimport imports data files into the database

Mysqlimport imports data files into the database

2022-07-06 17:44:00 Oh, no, I forgot my paper

matters needing attention 1:mysqlimport Import the data file into the corresponding table , Data file type support text,txt,csv, And the number of data file fields must be consistent with the number of table fields , The data file name must be consistent with the table name .

matters needing attention 2: Use mysqlimport It needs to be turned on when mysql Of local_inflie Parameters , by default off.

        Opening method 1:  Enter the database and execute  set global local_infile=1;
       			   Check the status ;
       			  mysql> show global variables like 'local_infile';
					+---------------+-------+
					| Variable_name | Value |
					+---------------+-------+
					| local_infile  | ON    |
					+---------------+-------+
					1 row in set (0.00 sec)

        Opening method 2: Edit database profile my.cnf, stay mysqld Add a line below  local_infile=ON;
       			  Restart the database to take effect ;
       			 systemctl restart mysqld
[[email protected] ~]# cat fa.txt 
3,zhanglei
4,lisi
[[email protected] ~]# mysqlimport -uroot -p --local test fa.txt --fields-terminated-by=','
Enter password: 
test.fa: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
[[email protected] ~]# mysql -uroot -p -e "select * from test.fa;"
Enter password: 
+----+----------+
| id | name     |
+----+----------+
|  3 | zhanglei |
|  4 | lisi     |
+----+----------+

  --local test fa.txt     test It's the name of the library  fa.txt It's the name of the file 
  --fields-terminated-by=','        Separator ,   

In the face of excel File is converted to txt perhaps csv When waiting for format , The encoding format should be UTF-8, The separator is a comma ;txt Wait for the file separator to write by yourself .

原网站

版权声明
本文为[Oh, no, I forgot my paper]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131309431754.html

随机推荐