准备数据库(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;