一次升級過程,在此記錄下。 原因:新的項目需要新的數(shù)據(jù)庫版本支持。 升級主要步驟: 備份原數(shù)據(jù)庫 ---》卸載mariadb ---》添加mariadb國內yum源 ---》安裝mariadb---》初始化數(shù)據(jù)庫---》導入數(shù)據(jù)。 1. 備份原數(shù)據(jù)庫 由于是對測試環(huán)境的數(shù)據(jù)庫進行升級,數(shù)據(jù)量不多,我直接導出需要遷移的數(shù)據(jù)庫的數(shù)據(jù)到sql文件里。 mysqldump -uroot -p --database database_name >name.sql 2. 卸載mariadb 由于是在同一臺服務器進行安裝新的Mariadb10.2,所以我們需要將老的版本卸載。 卸載mariadb: yum remove mariadb 刪除配置文件: rm -f /etc/my.cnf 刪除數(shù)據(jù)目錄: rm -rf /var/lib/mysql/ 3. 添加mariadb10.2的國內yum源 之前我添加的是國外的源,安裝很耗時,所以我找到國內yum源,通過這個源安裝較快。 vim /etc/yum.repos.d/Mariadb.repo 添加以下內容: [mariadb] name = MariaDB #baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64/ baseurl =https://mirrors.ustc.edu.cn/mariadb/yum/10.3/centos6-x86/ gpgkey=https://yum./RPM-GPG-KEY-MariaDB gpgcheck=1 清除yum源緩存數(shù)據(jù) yum clean all 生成新的yum源數(shù)據(jù)緩存 yum makecache all 官方y(tǒng)um源(國內安裝較慢)
官方不同系統(tǒng)yum源網(wǎng)址:https://downloads./mariadb/repositories/#mirror=tuna 4. 安裝mariadb10.2 yum install MariaDB-server MariaDB-client -y 啟動并添加開機自啟: systemctl start mariadb.service 5. mariadb的初始化 對數(shù)據(jù)庫進行一些基本設置: /usr/bin/mysql_secure_installation 一般建議按以下進行配置: Enter current password for root (enter for none): Just press the Enter button
Set root password? [Y/n]: YNew password: your-MariaDB-root-passwordRe-enter new password: your-MariaDB-root-passwordRemove anonymous users? [Y/n]: YDisallow root login remotely? [Y/n]: nRemove test database and access to it? [Y/n]: YReload privilege tables now? [Y/n]: Y 6. 導入數(shù)據(jù)到新版本mariadb 方法一: 登陸mysql后用source命令:(后面跟的是我們備份的sql文件的路徑) source /root/backup/java_api.sql 方法二: 在命令行直接導入 mysql -uroot -p >/root/backup/java_api.sql 以上就是整個版本升級的過程了。 作者:理想三旬 |
|