Menu Close

MariaDB 从5.5.64升级到10.6

参考官方文档:https://mariadb.com/kb/en/upgrading-from-mariadb-55-to-mariadb-100/

1. 备份数据库(全库)

重要的事情说三遍,备份,备份,备份

# 备份数据库,如果升级顺利是不要实施备份还原的
mysqldump -u root -p --all-databases > alldb.sql
# 如果想保留自己的my.cof配置,则备份一下这个文件
cp /etc/my.cnf /etc/my.cnf.bak
# 停止数据库运行
systemctl stop mariadb
# 卸载MariaDB老版本
yum remove mariadb mariadb-server

2. 添加 MariaDB Yum 库

建议使用MariaDB官方推荐的stable稳定版
https://downloads.mariadb.org/mariadb/
http://yum.mariadb.org/

# 添加MariaDB官方源
vim /etc/yum.repos.d/MariaDB.repo

# MariaDB 10.6 CentOS repository list
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.6/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

清除yum缓存

yum clean all
yum makecache

3. 升级已有数据库

3.1. 安装MariaDB新版本

yum install mariadb mariadb-server

3.2. 比较配置文件的差异,并修正数据文件路径等相关信息

vim -O /etc/my.cnf.bak /etc/my.cnf.d/server.cnf

3.3. 启动新版MariaDB

systemctl start mariadb

3.4. 升级已有数据库

mysql_upgrade -uroot -p

以下是升级数据库时显示的信息

]# mysql_upgrade -uroot -p
Enter password:
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.event                                        OK
mysql.func                                         OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.host                                         OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.servers                                      OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
Upgrading from a version before MariaDB-10.1
Phase 2/7: Installing used storage engines
Checking for tables with unknown storage engine
Phase 3/7: Fixing views
Phase 4/7: Running 'mysql_fix_privilege_tables'
Phase 5/7: Fixing table and database names
Phase 6/7: Checking and upgrading tables
Processing databases
information_schema
lccrepo
lccrepo.wp_commentmeta                             OK
lccrepo.wp_comments                                OK
lccrepo.wp_links                                   OK
lccrepo.wp_options                                 OK
lccrepo.wp_postmeta                                OK
lccrepo.wp_posts                                   OK
lccrepo.wp_term_relationships                      OK
lccrepo.wp_term_taxonomy                           OK
lccrepo.wp_termmeta                                OK
lccrepo.wp_terms                                   OK
lccrepo.wp_usermeta                                OK
lccrepo.wp_users                                   OK
performance_schema
sys
sys.sys_config                                     OK
test
Phase 7/7: Running 'FLUSH PRIVILEGES'
OK

3.5. 查看数据库版本

MariaDB [(none)]> select version();
+----------------+
| version()      |
+----------------+
| 10.6.3-MariaDB |
+----------------+
1 row in set (0.000 sec)

3.6. 设置数据库开机启动

systemctl enable mariadb