欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

项目从MYSQL迁移至MARIADB教程

程序员文章站 2024-02-04 20:38:46
准备数据库(mysql),若已有mysql,可忽略. build mysql table; 连接mysql; mysql -u root -p 创建数据表;...

准备数据库(mysql),若已有mysql,可忽略.

build mysql table;

连接mysql;

mysql -u root -p

创建数据表;

mysql> create database demo;

mysql> use demo;

mysql> create table pet(name varchar(30), owner varchar(30), species varchar(20), sex char(1));

添加数据表内容;

mysql> insert into pet values('brandon','jack','puddle','m'),('dixie','danny','chihuahua','f');

exit();     ----退出mysql

backup mysql;

前情提示,启用二进制;

备份数据表;备份my.cnf;

$ mysqldump --all-databases --user=root --password --master-data > backupdb.sql

$ sudo cp /etc/mysql/my.cnf /opt/my.cnf.bak



del mysql;

停止mysql服务;

$ sudo service mysql stop //rhel6

$ sudo systemctl stop mysql //rhel7

$ sudo /etc/init.d/mysql stop //rhel6

移除mysql配置及文件;

$ sudo yum remove mysql* mysql-server mysql-devel mysql-libs

$ sudo rm -rf /var/lib/mysql

build mariadb;

安装 mariadb;以及相关依赖包;

$ sudo vi /etc/yum.repos.d/mariadb.repo  //创建自定义的yum源

.......................................  //以下为文件内容

[mariadb]

name = mariadb

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

gpgkey=https://yum.mariadb.org/rpm-gpg-key-mariadb

gpgcheck=1

.......................................

$ sudo yum install mariadb-server mariadb-client//安装mariadb

恢复my.cnf文件;

$ sudo cp /opt/my.cnf   /etc/mysql/

启动mariadb;

$ sudo service mariadb start

$ sudo systemctl start mariadb

$ sudo /etc/init.d/mariadb start

mysql ==>> mariadb;

将数据表导入到mariadb中;

$ mysql -u root -p < backupdb.sql

出现一下内容,表示登录成功;恭喜你;

$ mysql -u root -p

......................................//以下为sql命令

mariadb [(none)]> show databases;

mariadb [(none)]> use test01;

mariadb [test01]> select * from pet;