如何把Access中數(shù)據(jù)導(dǎo)入Mysql中[手工]
版權(quán)聲明:該文為本人原創(chuàng),可以自由轉(zhuǎn)載,但不得用于商業(yè)途徑,并且需保留原作者名和本站地址.
參考資料:
1)mysql入門:http://space.lzu.edu.cn/homeof/usmot/bbs/show.asp?id=85
2)mysql數(shù)據(jù)類型:http://blog.xinweb.org/?action=show&id=20
3)mysql中文手冊(cè):http://www.linuxforum.net/books/mysqlmanual/manual_toc.html
4)mysql導(dǎo)入導(dǎo)出:http://it.yn.cninfo.net/pubnews/doc/read/8742421943220786691/103.oldsystem14.2635/index.asp
背景說明:
由于要做ftp搜索引擎的新版,即把目前VB+ACCESS+ASP的版本轉(zhuǎn)換成C+Mysql+PHP版
打算WEB開發(fā)和底層開發(fā)同時(shí)進(jìn)行
所以得先想辦法把Access中的數(shù)據(jù)轉(zhuǎn)到Mysql中
那么如何實(shí)現(xiàn)呢?
轉(zhuǎn)入正題
下面,一步一個(gè)腳印開始把Access數(shù)據(jù)轉(zhuǎn)換成Mysql的哦
第一步:
根據(jù)Access中數(shù)據(jù)庫(kù)的邏輯結(jié)構(gòu)[或者是以前寫好的數(shù)據(jù)庫(kù)設(shè)計(jì)文檔哦]
在Mysql下設(shè)計(jì)并創(chuàng)建出對(duì)應(yīng)的數(shù)據(jù)庫(kù)
先看看Access中的幾個(gè)表的結(jié)構(gòu),并進(jìn)行初步的數(shù)據(jù)類型轉(zhuǎn)換哦
site_tab //站點(diǎn)信息表
字段名稱 數(shù)據(jù)類型(Access) 數(shù)據(jù)類型(Mysql)
id 數(shù)字 int
site 文本 char(15)
port 數(shù)字 int
user 文本 char(15)
pw 文本 char(15)
acc 是/否 enum('N','Y')
indb 是/否 enum('N','Y')
info 備注 text
key_tab //關(guān)鍵字統(tǒng)計(jì)表
key 文本 char(100)
acctime 數(shù)字 int
file_tab //文件表
file Text(100) char(100)
postfix Text(4) char(4)
pid Integer int
ipid Integer int
acctime long int
cat_tab //目錄表
id Integer int
cat Text(100) char(100)
postfix Text(4) char(1) //這個(gè)可以考慮刪除掉,因?yàn)槎嘤?br>pid Integer int
ipid Integer int
acctime long int
下面根據(jù)上面的轉(zhuǎn)換,創(chuàng)建mysql下的數(shù)據(jù)庫(kù)和對(duì)應(yīng)的表項(xiàng)
[注意:上面涉及到的Mysql的數(shù)據(jù)類型可能選擇地不夠合適,需要日后調(diào)整]
先創(chuàng)建庫(kù),取名為falcon_search
create database falcon_search;
創(chuàng)建表site_tab
create table site_tab
(
id int not null primary key,
site char(15) not null,
port int default 21,
user char(15) not null default 'anonymous',
pw char(15) not null default 'falcon',
acc enum('N','Y') default 'N',
indb enum('N','Y') default 'N',
info text
);
創(chuàng)建表key_tab
create table key_tab
(
skey char(100) binary not null unique ,
acctime int default 0
);
創(chuàng)建表cat_tab
create table cat_tab
(
id int,
cat char(100) binary not null,
postfix char(1) binary,
pid int references cat_tab(id),
ipid int references site_tab(id),
acctime int,
primary key(id,ipid)
);
創(chuàng)建文件表file_tab
create table file_tab
(
file char(100) binary not null,
postfix char(4) binary not null,
pid int references cat_tab(id),
ipid int references site_tab(id),
acctime int
);
//由于文件重名的情況比較多,所以無須設(shè)置主關(guān)鍵字
第二步:
數(shù)據(jù)庫(kù)和表都創(chuàng)建好拉,我們現(xiàn)在得想辦法把數(shù)據(jù)從Access弄到Mysql下
怎么弄呢?
1)先把Access中的數(shù)據(jù)導(dǎo)出為txt文件[文本文件]
具體辦法:打開要操作的Access數(shù)據(jù)庫(kù)后,選擇"文件">>導(dǎo)出>>文本文件
在選擇導(dǎo)出后會(huì)彈出一個(gè)窗口,我們通過單擊"高級(jí)"設(shè)置其中的字段分割符為{tab},文本識(shí)別符號(hào)改成{無},當(dāng)然還可以進(jìn)行其他的設(shè)置哦.
注意:對(duì)應(yīng)的各個(gè)文件的文件名取名為對(duì)應(yīng)的表名哦(統(tǒng)一一下,方便后面操作)
2)之后,復(fù)制到mysql下的bin所在目錄下
第三步:
設(shè)法把文本文件中的數(shù)據(jù)導(dǎo)入到剛才創(chuàng)建的表中,要對(duì)應(yīng)起來哦
主要用到該句:LOAD DATA LOCAL IN FILE 存有數(shù)據(jù)的文本文件名 INTO TABLE 表名;
下面我們通過該辦法一個(gè)一個(gè)地把數(shù)據(jù)從文本文件中導(dǎo)入對(duì)應(yīng)的表中
1)site_tab.txt===>site_tab
load data local infile "site_tab.txt" into table site_tab;
ok,成功拉,不過好象有警告哦
我們先用select * site_tab;看看
原來,acc和indb全為空的
現(xiàn)在我們只要把a(bǔ)cc和indb的值更新為'N'就可以拉:
update site_tab set indb="N";
update site_tab set acc="N";
2)key_tab.txt===>key_tab
load data local infile "key_tab.txt" into table key_tab;
3)cat_tab.txt===>cat_tab
load data local infile "cat_tab.txt" into table cat_tab;
4)file_tab.txt===>file_tab
load data local infile "file_tab.txt" into table file_tab;
呵呵,ok,我們成功的把數(shù)據(jù)從Access導(dǎo)入到Mysql里頭拉
其實(shí)我們完全可以把這些操作更簡(jiǎn)化一些,有時(shí)間再弄,呵呵
兄弟姐妹們還有什么好的簡(jiǎn)單辦法,不妨到后面跟貼哦
關(guān)于把文本文件里頭的數(shù)據(jù)轉(zhuǎn)入postgresql中:
Quote: |
將SQLSERVER的數(shù)據(jù)導(dǎo)入到postgresql中 |
參考http://www.akae.cn/bbs/redirect.php?fid=24&tid=3584&goto=nextoldset
posted on 2008-03-14 16:16 隨意門 閱讀(512) 評(píng)論(0) 編輯 收藏 引用