Export Examples:Select *from Testinto outfile ' d:test.csv 'Fields terminated by ', ' optionally-enclosed by ' "' escaped by '" 'Lines terminated by ' \ r \ n ';Import Example:Load data infile ' D:test.csv 'into table ' test 'Fields terminated by ', ' optionally-enclosed by ' "' escaped by '" 'Lines terminated by ' \ n ' ignore 1 lines;The actual operation in accordance with this modification on the line, the problem of the place also hope to teach ~
The unified encoding method is Utf-8, and the CSV file encoding is set to Utf-8.
Create a new table in the database, column properties and CSV file to match, note the * * Month * * day, etc. in CSV set to date format, rather than strings, and so on, so you can import time.
Set to the selected time column, right-click
This article mainly introduces the PHP programming implementation of the CSV file import MySQL database method, involving PHP file reading, conversion, database connection, insert and other related operations skills, the need for friends can refer to the next
Specific as follows:
config.db.php content is as follows;
index.php content is as follows:
insertd
CVS file import mysql database command:
The code is as follows
Copy Code
Set names UTF8;LOAD DATA local INFILE ' c:\\resource.csv 'into TABLE ResourceFIELDS terminated by ""LINES terminated by ' \ r \ n '(Title,singer);
FIELDS terminated by----field terminating characterOptionally enclosed by----envelope characterLINES terminated by----line terminator
Export data for
Now all the content in the CSV file needs to be read and inserted into the database
Reply content:
Now all the content in the CSV file needs to be read and inserted into the database
You refer to Phpexcel This class library to see
$file = fopen (' xxx.csv ', ' R '), while ($data = Fgetcsv ($file)) { $result [] = $data;}//$result array is the content of CVS, put $ The result is good to save to the data
Label:1. Select database table--Right-click Properties--Backup/Export--export table data as---select CVS---Select the following "Change"--field--Variable length--field is terminated--input Comma, (this is the focus, otherwise the contents of the exported CSV file are in one column, not the sub-fields)The following two options boxes are canceled.2. After exporting the CSV file, use the UE editor to open, sav
1. Select database table--Right-click Properties--Backup/Export--export table data as---Select CVS--Select the following "Change"--field--Variable length--the field is terminated --Enter a comma, ( This is the focus, otherwise the contents of the exported CSV file are in one column, not the sub-field )The following two options boxes are canceled.2. after exporting the CSV file, use the UE editor to open, sa
Tags: pythonmysql The first part is how to handle the case where the number of columns in the data file is greater than the number of tables. Suppose the data file is as follows: Book1.csv number, name, Description 1, test data 1, "test CSV file with comma" 2, test Data 2, "The test CSV file has" "double quotes" "" 3, test Data 3, "Test
MySQL provides a tool for importing and exporting databases. However, sometimes we only need to import and export data from a single table, such as importing and exporting CSV files. In this case, you can use the MySQL Automatic Command to import and export data.
The export
Today, Kaggle downloaded from the CSV data into MySQL, want to do a statistical analysis, Zennai CSV file is somewhat large. So just use the MySQL command to import, now mark, for future contingencies:1. Import:基本的语法:load data [lo
1. First look at the data I need to import:When opened with Excel, displays:Open the display with notepad++ as:2. Use notepad++ to open change character set to UTF-83, create a table, the fields in the table to be consistent with the file3. Execute the command (my file is placed under local e-disk)LOAD DATA LOCAL INFILE ' e:/ihg_ipy20180405135615_bi.csv 'Into TABLE ' Ihg_hotel 'Fields TERMINATED by ', ' optionally-enclosed by ' "' escaped by '" 'LINES TERMINATED by ' \ r \ n 'IGNORE 1 rows;--nee
Now you need to read and insert all contents in the csv file into the database. now you need to read and insert all contents in the csv file into the database.
Reply content:
Now you need to read all the contents in the csv file and insert it to the database.
Please refer to the phpexcel class library.
$ File = fopen('xxx.csv ', 'r'); while ($ data = fget
1, Windows do CSV file by default is the GBK character set, and MySQL set the default is the UTF8 character set, so to convert the file to UTF8 format.Iconv-f gbk-t utf8/tmp/file name. csv-o/tmp/file name 2.csv2. Import with SQL commandLoad data infile '/tmp/mailut2.csv ' in
Note the encoding consistency, such as: My database is UTF-8 encoding, CSV document encoding is also utf-8.Import use LOAD DATA LOCAL INFILE For detailed usage please refer to documentation or books.MySQL User table structure:+----------+-------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+----------+-------------+------+-----+---------+---
Transferred from: http://codingstandards.iteye.com/blog/604541The sample SQL statements for exporting CSV format data in MySQL are as follows: Select from '/tmp/test.csv', ' " "'"'\ r \ n'The sample SQL statements for importing CSV format data in MySQL are as follows: ' /tmp/test.csv ' into table Test_info ' , '
At work, you often encounter the need to import data from a developer to a MySQL database, one of which is in CSV format and is imported as follows:Create the appropriate tablemysql>usekevin;databasechangedmysql>createtablegeopc_places ( ->isovarchar (2) NOTNULL,-> Countryvarchar (notnull,->languagevarchar) (2) Notnull,->idbigint (NOTNULL,) ->region1varchar, ->r
| | 0 | 0 |0 |+-----+-----+--------+--------+------+--------+------------+-------------+-----------+----------+-------+------------------------+-------+--------+-----+---------+----------+------+---------+------+-----+--------+---------+-------+-----+---------+-------------+--------------+---------------------------+-----------------------+1 row in Set (0.00 sec)There's only one piece of data in this table, and now I'm exporting a CSV file that only
Label:Transferred from: http://blog.chinaunix.net/uid-23284114-id-3196638.html The MYSQL LOAD Data infile command can import a CSV flat file into a database.Under Linux:
LOAD DATA INFILE '/home/test/dump/ip_location.csv '
Into TABLE ip_location
CHARACTER SET UTF8
Fields TERMINATED by ', ' enclosed by ' ";
--character Set:mysql Charact
MysqlimportExamplemysqlimport-uroot-p123456 Test/tmp/mytbl.txt;Convention: The last part of the file name is the table name, and the above statement is imported into the table MytblMysqlimport must specify the database, the above statement database is test
Import CSV
Mysqlimport-uroot-p--local--lines-terminated-by= "rn"--fields-terminated-by= ","--fields-enclosed-by= "" "Test/tmp /mytbl.csv
Load dataExam
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.