CentOS 7下MariaDB 5.5升级到MariaDB 10.2
转载自:https://cloud.tencent.com/developer/article/2075410
====================
一次CentOS 7下升级MariaDB过程,在此记录下。
原因:新的项目需要新的数据库版本支持。
升级主要步骤:
备份原数据库 ---》卸载mariadb ---》添加mariadb国内yum源 ---》安装mariadb---》初始化数据库---》导入数据。
1. 备份原数据库
由于是对测试环境的数据库进行升级,数据量不多,我直接导出需要迁移的数据库的数据到sql文件里。
mysqldump --skip-lock-tables -uroot -proot --database springboot > springboot.sql
2. 卸载mariadb
由于是在同一台服务器进行安装新的Mariadb10.2,所以我们需要将老的版本卸载。
卸载mariadb:
yum remove mariadb
删除配置文件:
rm -f /etc/my.cnf
删除数据目录:
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.2/centos7-amd64 gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck=1
清除yum源缓存数据
yum clean all
生成新的yum源数据缓存
yum makecache all
官方yum源(国内安装较慢)
# MariaDB 10.2 CentOS repository list - created 2018-06-06 03:42 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
官方不同系统yum源网址:https://downloads.mariadb.org/mariadb/repositories/#mirror=tuna
4. 安装mariadb10.2
yum install MariaDB-server MariaDB-client -y
启动并添加开机自启:
systemctl start mariadb.service systemctl enable mariadb.service
5. mariadb的初始化
/usr/bin/mysql_secure_installation
一般建议按以下进行配置:
Enter current password for root (enter for none): Just press the Enter button Set root password? [Y/n]: Y New password: your-MariaDB-root-password Re-enter new password: your-MariaDB-root-password Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: n Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y
6. 导入数据到新版本mariadb
方法一:
登陆mysql后用source命令:(后面跟的是我们备份的sql文件的路径)
source /tmp/springboot.sql
方法二:
在命令行直接导入
mysql -uroot -p >/root/backup/java_api.sql
以上就是整个版本升级的过程了。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示