上篇文章已經(jīng)講了如何在Centos6.4下安裝Redmine1.0并升級(jí)到3.3版本,那么應(yīng)用的升級(jí)完成之后,最重要的步驟,應(yīng)該就是數(shù)據(jù)庫(kù)的遷移了吧,畢竟數(shù)據(jù)才是整個(gè)過(guò)程中最重要的。
這一篇,就將數(shù)據(jù)庫(kù)的遷移分為兩部分來(lái)介紹過(guò)程,分別是本地升級(jí)和異地升級(jí)和遷移。
首先講講數(shù)據(jù)庫(kù)的本地升級(jí)吧:
redmine3.3版本升級(jí)完畢之后,此時(shí)本地的數(shù)據(jù)庫(kù)應(yīng)該是已經(jīng)初始化為3.3版本的數(shù)據(jù)庫(kù)結(jié)構(gòu)了之前這個(gè)命令創(chuàng)建的:RAILS_ENV=production bundle exec rake db:migrate
接下來(lái)要做的:
第一步.刪除3.3版本的redmine數(shù)據(jù)庫(kù),然后再新建數(shù)據(jù)庫(kù)
mysql -uroot -p
drop database redmine;
創(chuàng)建數(shù)據(jù)庫(kù)redmine和數(shù)據(jù)庫(kù):
create?database?redmine?character?set?utf8;
然后導(dǎo)入redmine1.0版本的數(shù)據(jù)庫(kù)sql文件
mysql -uusername -ppassword databasename < backupfile.sql
username =root,password = 自己設(shè)置的密碼
第二步:進(jìn)入redmine3.3目錄下,同步數(shù)據(jù)庫(kù)結(jié)構(gòu)
RAILS_ENV=production bundle exec rake db:migrate
然后就可以啟動(dòng)redmine了,進(jìn)入redmine3.3目錄下:
ruby bin/rails server webrick -e production
第二種:數(shù)據(jù)庫(kù)的異地升級(jí)和遷移:
我們把數(shù)據(jù)庫(kù)服務(wù)器叫服務(wù)器A,應(yīng)用服務(wù)器稱(chēng)為服務(wù)器B
首先,在服務(wù)器A上安裝mysql并創(chuàng)建Redmine數(shù)據(jù)庫(kù)和redmine用戶(hù)。
1.第一步:在數(shù)據(jù)庫(kù)服務(wù)器上安裝mysql并創(chuàng)建Redmine數(shù)據(jù)庫(kù)和redmine用戶(hù)。
yum -y install mysql mysql-server
chkconfig mysqld on
service mysqld start
給mysql數(shù)據(jù)庫(kù)設(shè)置密碼:命令:
/usr/bin/mysql_secure_installation
Because we not have a password for the root account so you press Enter to skip.
Enter current password for root (enter for none):
Select Yes to set the password for the MySQL root account.
Set root password? [Y/n] y
Enter and confirm your password, remove the anonymous user, select Yes
Remove anonymous users? [Y/n] y
Allow remote login to MySQL as root account, select No.
Disallow root login remotely? [Y/n] n
Delete the test database, select Yes
Remove test database and access to it? [Y/n] y
Reload privilege tables, select Yes
Reload privilege tables now? [Y/n] y
創(chuàng)建redmine數(shù)據(jù)庫(kù)和用戶(hù):因?yàn)閞edmine的web服務(wù)器和數(shù)據(jù)庫(kù)服務(wù)器不在同一臺(tái)機(jī)器上,所以使用%代替了localhost
1.mysql?-uroot?-p?#首次mysql的密碼為空
2.create?database?redmine?character?set?utf8;
3.create?user?'redmine'@'%'?IDENTIFIED?BY?'pwd';?#用戶(hù)名:?redmine;?密碼:pwd
4.grant?all?privileges?on?redmine.*?to?'redmine'@'%';?#最大權(quán)限
5.flush?privileges;
在服務(wù)器B上修改database.yml文件:
host改為服務(wù)器A的地址。
至此,數(shù)據(jù)庫(kù)服務(wù)器上產(chǎn)生了redmine的表。
第二步:數(shù)據(jù)庫(kù)的導(dǎo)入
在原redmine服務(wù)器上x(chóng)p系統(tǒng)上,關(guān)閉redmine服務(wù),以免備份過(guò)程中數(shù)據(jù)不完整
關(guān)掉下列服務(wù):
redmineApache
redmineSubversion
redmineThin1
redmineThin2
進(jìn)入mysql/bin目錄下:備份現(xiàn)有的數(shù)據(jù)庫(kù)
mysqldump -uusername -ppassword databasename > backupfile.sql
***username =root,password =自己設(shè)置的密碼
導(dǎo)入到目標(biāo)數(shù)據(jù)庫(kù)服務(wù)器:
mysql -hhostname -uusername -ppassword databasename < backupfile.sql
***Hostname=目標(biāo)服務(wù)器A的地址,
***username=redmine,password= pwd;
第三步:
在web服務(wù)器下的
redmine目錄下執(zhí)行:
RAILS_ENV=production bundle exec rake db:migrate//創(chuàng)建數(shù)據(jù)庫(kù)結(jié)構(gòu)
RAILS_ENV=production bundle exec rake redmine:load_default_data//初始化表結(jié)構(gòu)
將原redmine目錄下的file文件拷貝至redmine3.3版本的file文件夾下。
rm -rf /usr/local/redmine3.3/files
mv /files的路徑/files /usr/local/redmine3.3/
至此,redmine的數(shù)據(jù)庫(kù)異地升級(jí)和遷移完成。
小結(jié):先導(dǎo)入數(shù)據(jù)庫(kù).sql文件,再執(zhí)行RAILS_ENV=production bundle exec rake db:migrate,可實(shí)現(xiàn)數(shù)據(jù)庫(kù)的結(jié)構(gòu)升級(jí)。