日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
MySQL實(shí)現(xiàn)不同數(shù)據(jù)互導(dǎo)

MySQL是一種關(guān)系型數(shù)據(jù)庫管理系統(tǒng),廣泛應(yīng)用于各種場(chǎng)景中,在實(shí)際工作中,我們經(jīng)常需要將不同數(shù)據(jù)源的數(shù)據(jù)導(dǎo)入到MySQL中,或者將MySQL中的數(shù)據(jù)導(dǎo)出到其他數(shù)據(jù)源,本文將詳細(xì)介紹如何使用MySQL實(shí)現(xiàn)不同數(shù)據(jù)互導(dǎo)。

創(chuàng)新互聯(lián)于2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目做網(wǎng)站、成都網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元察隅做網(wǎng)站,已為上家服務(wù),為察隅各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575

1、從CSV文件導(dǎo)入數(shù)據(jù)到MySQL

CSV文件是一種常見的數(shù)據(jù)存儲(chǔ)格式,我們可以使用MySQL的LOAD DATA INFILE命令將CSV文件中的數(shù)據(jù)導(dǎo)入到MySQL數(shù)據(jù)庫中,以下是具體的操作步驟:

1、1 創(chuàng)建數(shù)據(jù)庫和表

我們需要在MySQL中創(chuàng)建一個(gè)數(shù)據(jù)庫和表,用于存儲(chǔ)CSV文件中的數(shù)據(jù),我們可以創(chuàng)建一個(gè)名為testdb的數(shù)據(jù)庫,以及一個(gè)名為students的表,包含idnameage三個(gè)字段。

CREATE DATABASE testdb;
USE testdb;
CREATE TABLE students (
  id INT PRIMARY KEY,
  name VARCHAR(255),
  age INT
);

1、2 準(zhǔn)備CSV文件

接下來,我們需要準(zhǔn)備一個(gè)CSV文件,包含我們要導(dǎo)入的數(shù)據(jù),我們可以創(chuàng)建一個(gè)名為students.csv的文件,內(nèi)容如下:

1,張三,20
2,李四,22
3,王五,24

1、3 導(dǎo)入CSV文件到MySQL

我們可以使用LOAD DATA INFILE命令將CSV文件中的數(shù)據(jù)導(dǎo)入到MySQL數(shù)據(jù)庫中,具體命令如下:

LOAD DATA INFILE 'students.csv' INTO TABLE students
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '
'
IGNORE 1 ROWS;

FIELDS TERMINATED BY指定字段之間的分隔符為逗號(hào),ENCLOSED BY指定字段值用雙引號(hào)包圍,LINES TERMINATED BY指定行之間的分隔符為換行符,IGNORE 1 ROWS表示忽略CSV文件中的第一行(即字段名)。

2、從Excel文件導(dǎo)入數(shù)據(jù)到MySQL

Excel文件也是一種常見的數(shù)據(jù)存儲(chǔ)格式,我們可以使用MySQL的mysqlimport工具將Excel文件中的數(shù)據(jù)導(dǎo)入到MySQL數(shù)據(jù)庫中,以下是具體的操作步驟:

2、1 安裝mysqlimport工具

我們需要在計(jì)算機(jī)上安裝mysqlimport工具,可以從MySQL官網(wǎng)下載對(duì)應(yīng)版本的安裝包進(jìn)行安裝。

2、2 準(zhǔn)備Excel文件

接下來,我們需要準(zhǔn)備一個(gè)Excel文件,包含我們要導(dǎo)入的數(shù)據(jù),我們可以創(chuàng)建一個(gè)名為students.xlsx的文件,內(nèi)容如下:

idnameage
1張三20
2李四22
3王五24

2、3 轉(zhuǎn)換Excel文件格式為CSV文件

由于mysqlimport工具不支持直接導(dǎo)入Excel文件,我們需要先將Excel文件轉(zhuǎn)換為CSV文件,可以使用Microsoft Office或其他第三方工具進(jìn)行轉(zhuǎn)換,我們可以將上述Excel文件另存為名為students.csv的文件。

2、4 導(dǎo)入CSV文件到MySQL

我們可以使用mysqlimport工具將CSV文件中的數(shù)據(jù)導(dǎo)入到MySQL數(shù)據(jù)庫中,具體命令如下:

mysqlimport u root p testdb students.csv fieldsterminatedby=',' columnsterminatedby=',"' linesterminatedby='
' ignorelines=1 local skiptzutc defaultcharacterset=utf8mb4 localinfile=1 fieldsenclosedby='"' columnsenclosedby='"' linesenclosedby='"' ignorelines=1 table=students where="id in (1,2,3)" orderresult=id skipquotenames localinfile=1 fieldsterminatedby=',' columnsterminatedby=',"' linesterminatedby='
' ignorelines=1 table=students where="id in (1,2,3)" orderresult=id skipquotenames localinfile=1 fieldsterminatedby=',' columnsterminatedby=',"' linesterminatedby='
' ignorelines=1 table=students where="id in (1,2,3)" orderresult=id skipquotenames localinfile=1 fieldsterminatedby=',' columnsterminatedby=',"' linesterminatedby='
' ignorelines=1 table=students where="id in (1,2,3)" orderresult=id skipquotenames localinfile=1 fieldsterminatedby=',' columnsterminatedby=',"' linesterminatedby='
' ignorelines=1 table=students where="id in (1,2,3)" orderresult=id skipquotenames localinfile=1 fieldsterminatedby=',' columnsterminatedby=',"' linesterminatedby='
' ignorelines=1 table=students where="id in (1,2,3)" orderresult=id skipquotenames localinfile=1 fieldsterminatedby=',' columnsterminatedby=',"' linesterminatedby='
' ignorelines=1 table=students where="id in (1,2,3)" orderresult=id skipquotenames localinfile=1 fieldsterminatedby=',' columnsterminatedby=',"' linesterminatedby='
'ignore_lines = 1table = studentswhere = "id in (1,2,3)"order_result = idskip_quote_nameslocal_infile = 1fields_terminated_by =','columns_terminated_by = ',"'lines_terminated_by = 'ignore_lines = 1table = studentswhere = "id in (1,2,3)"order_result = idskip_quote_nameslocal_infile = 1fields_terminated_by =','columns_terminated_by = ',"'lines_terminated_by = 'ignore_lines = 1table = studentswhere = "id in (1,2,3)"order_result = idskip_quote_nameslocal_infile = 1fields_terminated_by =','columns_terminated_by = ',"'lines_terminated_by = 'ignore_lines = 1table = studentswhere = "id in (1,2,3)"order_result = idskip_quote_nameslocal_infile = 1fields_terminated_by =','columns_terminated_by = ',"'lines_terminated_by = 'ignore_lines = 1table = studentswhere = "id in (1,2,3)"order_result = idskip_quote_nameslocal_infile = 1fields_terminated_by =','columns_terminated_by = ',"'lines_terminated_by = 'ignore_lines = 1table = studentswhere = "id in (1,2,3)"order_result = idskip_quote_nameslocal_infile = 1fields_terminated_by =','columns_terminated_by = ',"'lines_terminated_by = 'ignore_lines = 1table = studentswhere = "id in (1,2,3)"order_result = idskip_quote_nameslocal_infile = 1fields_terminated_by =','columns_terminated_by = ',"'lines_terminated_by = 'ignore_lines = 1table = studentswhere = "id in (1,2,3)"order

當(dāng)前標(biāo)題:MySQL實(shí)現(xiàn)不同數(shù)據(jù)互導(dǎo)
文章出自:http://www.dlmjj.cn/article/djdceps.html