MariaDB 数据库升级版本
Posted 愿许浪尽天涯
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MariaDB 数据库升级版本相关的知识,希望对你有一定的参考价值。
1)安装旧版本数据库(如果已经安装,可直接跳过)
[root@localhost ~]# wget https://dlm.mariadb.com/1657824/MariaDB/mariadb-10.4.19/bintar-linux-x86_64/mariadb-10.4.19-linux-x86_64.tar.gz
[root@localhost ~]# tar xf mariadb-10.4.19-linux-x86_64.tar.gz
[root@localhost ~]# mv mariadb-10.4.19-linux-x86_64 /usr/local/mariadb
[root@localhost ~]# cd /usr/local/mariadb
[root@localhost mariadb]# useradd -s /sbin/nologin mysql -M
[root@localhost mariadb]# sed -i 's#^basedir=#basedir=/usr/local/mariadb#' support-files/mysql.server
[root@localhost mariadb]# sed -i 's#^datadir=#datadir=/usr/local/mariadb/data#' support-files/mysql.server
[root@localhost mariadb]# ./scripts/mysql_install_db --basedir=/usr/local/mariadb --datadir=/usr/local/mariadb/data --user=mysql
[root@localhost mariadb]# cat <<END > my.cnf
[mysqld]
port=3306
skip-name-resolve
max_connections=20000
server-id=1
log-bin=mysql-bin
expire_logs_days=14
binlog_format=ROW
END
[root@localhost mariadb]# rm -rf /etc/my.cnf
[root@localhost mariadb]# chown -R mysql:mysql .
[root@localhost mariadb]# ./support-files/mysql.server start
2)准备新版本数据库,并备份旧的数据库目录
[root@localhost ~]# wget https://dlm.mariadb.com/2258065/MariaDB/mariadb-10.4.25/bintar-linux-x86_64/mariadb-10.4.25-linux-x86_64.tar.gz
[root@localhost ~]# tar xf mariadb-10.4.25-linux-x86_64.tar.gz
[root@localhost ~]# /usr/local/mariadb/support-files/mysql.server stop # 关闭数据库
[root@localhost ~]# nohup cp -r /usr/local/mariadb /usr/local/mariadb-$(date +%F) &
- 上面备份的时候,需要等数据库进程完全退出后,在进行备份(因为未退出的数据库进程可能还会造成数据产生)
3)升级
其实升级数据库,只需要将旧版本数据库的 data
目录放到新版本数据库的目录下即可。 下面我们将与 data
目录无关的目录移走,是因为当 data
目录较大时,移动起来就会比较慢,因此通过移走别的目录,来缩短升级所需要的时间。
[root@localhost ~]# cd /usr/local/mariadb
[root@localhost mariadb]# mkdir backup
[root@localhost mariadb]# ls | egrep -v 'backup|data|my.cnf' > /root/1.txt
[root@localhost mariadb]# for i in $(cat /root/1.txt);do mv $i backup/;done
[root@localhost mariadb]# rm -rf /root/mariadb-10.4.25-linux-x86_64/data # 这里删除的是新包里面的 data 目录
[root@localhost mariadb]# cp -r /root/mariadb-10.4.25-linux-x86_64/* .
[root@localhost mariadb]# chown -R mysql:mysql .
[root@localhost mariadb]# sed -i 's#^basedir=#basedir=/usr/local/mariadb#' support-files/mysql.server
[root@localhost mariadb]# sed -i 's#^datadir=#datadir=/usr/local/mariadb/data#' support-files/mysql.server
[root@localhost mariadb]# ./support-files/mysql.server start
[root@localhost mariadb]# ./bin/mysql_upgrade -uroot --force
验证:
[root@localhost mariadb]# /usr/local/mariadb/bin/mysql -V
升级过程可能出现的问题:
1)输出:
...
ERROR 1932 (42S02): at line 603: Table 'mysql.innodb_table_stats' doesn't exist in engine
FATAL ERROR: Upgrade failed
上面的报错是因为数据库里面的表损坏了,在数据库里将损坏的表删除后,重新升级即可
MariaDB [(none)]> drop table mysql.innodb_table_stats;
Query OK, 0 rows affected (0.001 sec)
[root@localhost mariadb]# rm -rf /usr/local/mariadb/data/mysql/innodb_table_stats.ibd
2)输出:
Error: Server version (10.4.19-MariaDB-log) does not match with the version of
the server (10.4.25-MariaDB) with which this program was built/distributed. You can
use --skip-version-check to skip this check.
FATAL ERROR: Upgrade failed
- 上面报错是因为我们替换完二进制包后,并没有对数据库进行重启导致的,可以通过
--skip-version-check
来跳过检查。
[root@localhost ~]# /usr/local/mariadb/bin/mysql_upgrade -uroot --skip-version-check
以上是关于MariaDB 数据库升级版本的主要内容,如果未能解决你的问题,请参考以下文章
mysql 5.1 升级 mysql 5.7 升级 mariadb10
centos7 Mariadb5.5升级到Mariadb10.2