centos7升级mariadb

1、备份原数据库

按数据库名导出:mysqldump -uroot -p --database database_name >name.dump

导出所有数据库:mysqldump -u root -p --all-databases > alldb.sql

如出错,尝试这个:mysqldump --single-transaction -u root -p --all-databases> alldb.sql

2、停止服务运行

systemctl stop mariadb && systemctl status mariadb

3、卸载mariadb

yum remove -y mariadb &&yum remove -y mariadb-*

4、查找安装信息并删除

yun list installed |grep mariadb 
rpm -qa |grep mariadb 
find / -name mysql 
find / -name mariadb 
删除配置文件:rm -f /etc/my.cnf 
删除数据目录:rm -rf /var/lib/mysql

5、添加国内yum源

vim /etc/yum.repos.d/Mariadb.repo

添加以下内容:

# MariaDB 11.0 CentOS repository list - created 2023-06-17 03:06 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# baseurl = https://rpm.mariadb.org/11.0/centos/$releasever/$basearch
baseurl = https://mirrors.neusoft.edu.cn/mariadb/yum/11.0/centos/$releasever/$basearch
module_hotfixes = 1
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirrors.neusoft.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
 

 
  

官方yum源(国内安装较慢)
Download MariaDB Server - MariaDB.org

 
  

[mariadb] name = MariaDB

baseurl = http://yum.mariadb.org/10.2/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

6、清除yum源缓存数据,并生成新的yum源数据缓存

yum clean all && yum makecache all
查看下载缓存信息:ll /var/cache/yum/x86_64/7/mariadb

7、安装mariadb

yum install MariaDB-server MariaDB-client -y

启动并添加开机自启:

systemctl start mariadb
systemctl enable mariadb

8、mariadb初始化

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

9、导入数据到新版本mariadb

方法一:

登陆mysql后用source命令:(后面跟的是我们备份的sql文件的路径)

source /root/backup/java_api.sql

方法二:

在命令行直接导入

mysql -uroot -p >/root/backup/java_api.sql

以上就是整个版本升级的过程了。

你可能感兴趣的:(linux,mariadb,运维)