MariaDB-5.5.65至MariaDB-10.4.12的升级步骤
备份旧数据库
# mysqldump -uroot -p dbname > /var/www/db.sql
停止服务
# systemctl stop mariadb
卸载旧版本
查看相关包
# rpm -aq|grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
mariadb-5.5.65-1.el7.x86_64
mariadb-server-5.5.65-1.el7.x86_64
移除相关包
# yum -y remove mariadb*
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.65-1.el7 will be erased
---> Package mariadb-libs.x86_64 1:5.5.65-1.el7 will be erased
安装新版本
最新版本包源
# vim /etc/yum.repos.d/MariaDB.repo
输入最新版本包源信息
[mariadb]
name = MariaDB
baseurl = http://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/
gpgkey = http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
清理yum并重新加载yum
# yum clean all
# yum makecache
安装MariaDB
# yum install MariaDB-server MariaDB-client -y
设置开机启动服务 启动服务
# systemctl enable mariadb
# systemctl start mariadb
还原数据库
进入数据库
# mysql -uroot -p
查看现版本
MariaDB [(none)]> select version();
+-----------------+
| version() |
+-----------------+
| 10.4.12-MariaDB |
+-----------------+
创建数据库和用户
MariaDB [(none)] use mysql;
MariaDB [mysql] create database dbname;
MariaDB [mysql] create user 'username'@'%' identified by 'pwd';
dbname为数据库名,username为用户名,pwd为密码
如果本地访问,%换为localhost
MariaDB [mysql] create user 'username'@'localhost' identified by 'pwd';
给新用户授权
MariaDB [mysql] grant ALL on dbname.* to 'username'@'%';
导入数据库脚本
MariaDB [mysql] use dbname;
MariaDB [dbname] source /var/www/db.sql;