mysql升级到mariadb[同一台机器上]

---恢复内容开始---

操作系统:centos6.5

即将安装的数据库软件:mysql 5.1和 mariadb 10.3.8

注意事项:mysql的端口不能和mariadb端口一样,否则无法启动

我这里mysql采用默认端口:3306

mariadb的端口我会指定为:3307

1,配置yum源便于用yum进行安装软件

下面是我的/etc/yum.repos.d/Centos-Base.repo仓库文件的内容

[[email protected] ~]# cat /etc/yum.repos.d/CentOS6-Base-163.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-6 - Base - 163.com
baseurl=http://mirrors.163.com/centos/6/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-6 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

2,安装mysql

yum安装的过程已经省略,只给出安装指令

[[email protected] ~]# yum -y install mysql-server mysql

3,检查是否可以启动mysql并连接

下图可以看见直接敲mysql指令就进入了数据库,这时因为刚安装好之后还没有设置密码

[[email protected] ~]# ls /etc/init.d/mysql*/etc/init.d/mysqld[[email protected] ~]# service mysqld start正在启动 mysqld:                                          [确定][[email protected] ~]# [[email protected] ~]# [[email protected] ~]# mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> quit

4,下载并编译安装mariadb10.3.8

官网下载地址:

https://downloads.mariadb.org/interstitial/mariadb-10.3.8/source/mariadb-10.3.8.tar.gz/from/http%3A//mirrors.tuna.tsinghua.edu.cn/mariadb/

在浏览器里打开后可能需要你填信息,信息随便填假信息也可以,但得符合格式,人家让你填电话你就别傻到填字母就行

下载后进行解压并安装

[[email protected] ~]# ls /home/ting/下载/mariadb-*
/home/ting/下载/mariadb-10.3.8.tar.gz
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# cd /root
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# tar -xf mariadb-10.3.8.tar.gz
[[email protected] ~]#
[[email protected] ~]#

编译安装之前需要安装编译环境

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# yum -y install gcc gcc-c++ cmake bison bison-devel ncurses-devel openssl-devel openssl

开始编译安装

[[email protected] mariadb-10.3.8]#
[[email protected] mariadb-10.3.8]#
[[email protected] mariadb-10.3.8]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DMYSQL_DATADIR=/var/lib/mariadb -DSYSCONFDIR=/etc/mariadb -DWITHOUT_TOKUDB=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_HEADLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/var/lib/mariadb/mariadb.sock -DMYSQL_TCP_PORT=3307 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
[[email protected] mariadb-10.3.8]#
[[email protected] mariadb-10.3.8]# make
[[email protected] mariadb-10.3.8]#
[[email protected] mariadb-10.3.8]# make install

5,编写mariadb的启动管理脚本

目的是便于启动或停止mariadb

编写之前先建立相关目录和授权

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# mkdir /var/lib/mariadb
[[email protected] ~]#
[[email protected] ~]# mkdir /var/run/mariadb
[[email protected] ~]#
[[email protected] ~]# mkdir /var/log/mariadb
[[email protected] ~]#
[[email protected] ~]# chown mysql.mysql  /var/lib/mariadb
[[email protected] ~]#
[[email protected] ~]# chown mysql.mysql /var/run/mariadb
[[email protected] ~]#
[[email protected] ~]# chown mysql.mysql /var/log/mariadb

开始编写mariadb启动管理脚本,脚本内容如下:

我这而脚本名称是:mariadb

cat mariadb的内容如下:

#!/bin/bash
#
# chkconfig: 2345 10 90
# description: mariadb service manager
# Usage: service mariadb <status | start | stop | restart>

port=3307
basedir=/usr/local/mariadb
datadir=/var/lib/mariadb
u=mysql
log_err=/var/log/mariadb/mariadb_err.log
pid_file=/var/run/mariadb/mariadb.pid
sock=/var/lib/mariadb/mariadb.sock

function check(){
mysql_proc_num=`ps -ef|grep ‘mysqld ‘|grep mariadb|grep -v grep|wc -l`
mysql_proc_pid=`ps -ef|grep ‘mysqld ‘|grep mariadb|grep -v grep|awk ‘{print $2}‘`
if [ -f $pid_file ]
then
pid_file_pid=`cat $pid_file`
else
echo "MariaDB stopped ..."
return
fi

if [ $mysql_proc_pid -eq $pid_file_pid ] && [ $mysql_proc_num -ne 0 ]
then
echo "MariaDB is running ..."
else
echo "MariaDB stopped ..."
fi
}

function start(){
cd $basedir
./bin/mysqld_safe --datadir=$datadir --user=u --log-error=$log_err --pid-file=$pid_file --socket=$sock --port=$port &
sleep 3;
check;
}

function stop(){
kill  `cat $pid_file`
sleep 2;
check;
}

function restart(){
kill -HUP `cat $pid_file`
sleep 2
echo -e "重启完毕:\c "
check;
}

function status(){
check;
}

case $1 in
status)
status;;
stop)
stop;;
start)
start;;
restart)
restart;;
*)
echo "用法1:/etc/init.d/mariadb <status | stop | start | restart>"
echo "用法2:service mariadb <status | stop | start | restart>"
;;
esac

6,将脚本移动到/etc/init.d/目录下去

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# cp mariadb /etc/init.d/
[[email protected] ~]#
[[email protected] ~]# chmod +x /etc/init.d/mariadb
[[email protected] ~]#
[[email protected] ~]#

7,检查mariadb服务是否可以正常运行并连接

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# ls -l /etc/init.d/mar*
-rwxr-xr-x. 1 root root 1303 8月   7 23:39 /etc/init.d/mariadb
[[email protected] ~]#
[[email protected] ~]# service mariadb start
180807 23:42:42 mysqld_safe Logging to ‘/var/log/mariadb/mariadb_err.log‘.
180807 23:42:42 mysqld_safe Starting mysqld daemon with databases from /var/lib/mariadb
MariaDB is running ...
[[email protected] ~]#
[[email protected] ~]# ps -ef|grep mariadb
root      7261     1  0 23:42 pts/2    00:00:00 /bin/sh ./bin/mysqld_safe --datadir=/var/lib/mariadb --user=u --log-error=/var/log/mariadb/mariadb_err.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mariadb/mariadb.sock --port=3307
mysql     7365  7261  3 23:42 pts/2    00:00:00 /usr/local/mariadb/bin/mysqld --basedir=/usr/local/mariadb --datadir=/var/lib/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=u --log-error=/var/log/mariadb/mariadb_err.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mariadb/mariadb.sock --port=3307
root      7411  7054  0 23:42 pts/2    00:00:00 grep mariadb
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# /usr/local/mariadb/bin/mysql -P 3307
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.8-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> quit

8,设置mysql和mariadb的数据库密码

设置mysql的密码

[[email protected] ~]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password(‘123456‘) where user=‘root‘;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2  Changed: 0  Warnings: 0

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql>

设置mariadb的密码

[[email protected] ~]#
[[email protected] ~]# /usr/local/mariadb/bin/mysql -P 3307
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 10.3.8-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> update user set password=password(‘123456‘) where user=‘root‘;
Query OK, 0 rows affected (0.045 sec)
Rows matched: 2  Changed: 0  Warnings: 0

MariaDB [mysql]> commit;
Query OK, 0 rows affected (0.000 sec)

MariaDB [mysql]> quit

现在设在完了再不能无密码登录了,都需要-p参数指定密码才行

9,开始升级操作

升级之前肯定要先迁移数据

先导出mysql所有库的数据

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# mysqldump -A -uroot -p123456 >all.sql
[[email protected] ~]# 

10,导入mysql说有数据到mariadb中

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# /usr/local/mariadb/bin/mysql -h 127.0.0.1 -P 3307 <all.sql
[[email protected] ~]#
 

11,验证是否导入成功,且mariadb是否正常

由下面可以看出mariadb没有异常,并且mysql的tmp1库也迁移到了mariadb中,1000条数据也都存在

注:我已经事先在mysql中创建量tmp1库,并建立了1个stu表,插入了1000条数据。

[[email protected] ~]# /usr/local/mariadb/bin/mysql -P 3307 -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.3.8-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| tmp1               |
+--------------------+
5 rows in set (0.001 sec)

MariaDB [(none)]> use tmp1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [tmp1]> show tables;
+----------------+
| Tables_in_tmp1 |
+----------------+
| stu            |
+----------------+
1 row in set (0.001 sec)

MariaDB [tmp1]> select count(*) from stu;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.001 sec)

MariaDB [tmp1]> quit

---恢复内容结束---

操作系统:centos6.5

即将安装的数据库软件:mysql 5.1和 mariadb 10.3.8

注意事项:mysql的端口不能和mariadb端口一样,否则无法启动

我这里mysql采用默认端口:3306

mariadb的端口我会指定为:3307

1,配置yum源便于用yum进行安装软件

下面是我的/etc/yum.repos.d/Centos-Base.repo仓库文件的内容

[[email protected] ~]# cat /etc/yum.repos.d/CentOS6-Base-163.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-6 - Base - 163.com
baseurl=http://mirrors.163.com/centos/6/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-6 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

2,安装mysql

yum安装的过程已经省略,只给出安装指令

[[email protected] ~]# yum -y install mysql-server mysql

3,检查是否可以启动mysql并连接

下图可以看见直接敲mysql指令就进入了数据库,这时因为刚安装好之后还没有设置密码

[[email protected] ~]# ls /etc/init.d/mysql*/etc/init.d/mysqld[[email protected] ~]# service mysqld start正在启动 mysqld:                                          [确定][[email protected] ~]# [[email protected] ~]# [[email protected] ~]# mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> quit

4,下载并编译安装mariadb10.3.8

官网下载地址:

https://downloads.mariadb.org/interstitial/mariadb-10.3.8/source/mariadb-10.3.8.tar.gz/from/http%3A//mirrors.tuna.tsinghua.edu.cn/mariadb/

在浏览器里打开后可能需要你填信息,信息随便填假信息也可以,但得符合格式,人家让你填电话你就别傻到填字母就行

下载后进行解压并安装

[[email protected] ~]# ls /home/ting/下载/mariadb-*
/home/ting/下载/mariadb-10.3.8.tar.gz
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# cd /root
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# tar -xf mariadb-10.3.8.tar.gz
[[email protected] ~]#
[[email protected] ~]#

编译安装之前需要安装编译环境

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# yum -y install gcc gcc-c++ cmake bison bison-devel ncurses-devel openssl-devel openssl

开始编译安装

[[email protected] mariadb-10.3.8]#
[[email protected] mariadb-10.3.8]#
[[email protected] mariadb-10.3.8]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DMYSQL_DATADIR=/var/lib/mariadb -DSYSCONFDIR=/etc/mariadb -DWITHOUT_TOKUDB=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_HEADLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/var/lib/mariadb/mariadb.sock -DMYSQL_TCP_PORT=3307 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
[[email protected] mariadb-10.3.8]#
[[email protected] mariadb-10.3.8]# make
[[email protected] mariadb-10.3.8]#
[[email protected] mariadb-10.3.8]# make install

5,编写mariadb的启动管理脚本

目的是便于启动或停止mariadb

编写之前先建立相关目录和授权

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# mkdir /var/lib/mariadb
[[email protected] ~]#
[[email protected] ~]# mkdir /var/run/mariadb
[[email protected] ~]#
[[email protected] ~]# mkdir /var/log/mariadb
[[email protected] ~]#
[[email protected] ~]# chown mysql.mysql  /var/lib/mariadb
[[email protected] ~]#
[[email protected] ~]# chown mysql.mysql /var/run/mariadb
[[email protected] ~]#
[[email protected] ~]# chown mysql.mysql /var/log/mariadb

开始编写mariadb启动管理脚本,脚本内容如下:

我这而脚本名称是:mariadb

cat mariadb的内容如下:

#!/bin/bash
#
# chkconfig: 2345 10 90
# description: mariadb service manager
# Usage: service mariadb <status | start | stop | restart>

port=3307
basedir=/usr/local/mariadb
datadir=/var/lib/mariadb
u=mysql
log_err=/var/log/mariadb/mariadb_err.log
pid_file=/var/run/mariadb/mariadb.pid
sock=/var/lib/mariadb/mariadb.sock

function check(){
mysql_proc_num=`ps -ef|grep ‘mysqld ‘|grep mariadb|grep -v grep|wc -l`
mysql_proc_pid=`ps -ef|grep ‘mysqld ‘|grep mariadb|grep -v grep|awk ‘{print $2}‘`
if [ -f $pid_file ]
then
pid_file_pid=`cat $pid_file`
else
echo "MariaDB stopped ..."
return
fi

if [ $mysql_proc_pid -eq $pid_file_pid ] && [ $mysql_proc_num -ne 0 ]
then
echo "MariaDB is running ..."
else
echo "MariaDB stopped ..."
fi
}

function start(){
cd $basedir
./bin/mysqld_safe --datadir=$datadir --user=u --log-error=$log_err --pid-file=$pid_file --socket=$sock --port=$port &
sleep 3;
check;
}

function stop(){
kill  `cat $pid_file`
sleep 2;
check;
}

function restart(){
kill -HUP `cat $pid_file`
sleep 2
echo -e "重启完毕:\c "
check;
}

function status(){
check;
}

case $1 in
status)
status;;
stop)
stop;;
start)
start;;
restart)
restart;;
*)
echo "用法1:/etc/init.d/mariadb <status | stop | start | restart>"
echo "用法2:service mariadb <status | stop | start | restart>"
;;
esac

6,将脚本移动到/etc/init.d/目录下去

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# cp mariadb /etc/init.d/
[[email protected] ~]#
[[email protected] ~]# chmod +x /etc/init.d/mariadb
[[email protected] ~]#
[[email protected] ~]#

7,检查mariadb服务是否可以正常运行并连接

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# ls -l /etc/init.d/mar*
-rwxr-xr-x. 1 root root 1303 8月   7 23:39 /etc/init.d/mariadb
[[email protected] ~]#
[[email protected] ~]# service mariadb start
180807 23:42:42 mysqld_safe Logging to ‘/var/log/mariadb/mariadb_err.log‘.
180807 23:42:42 mysqld_safe Starting mysqld daemon with databases from /var/lib/mariadb
MariaDB is running ...
[[email protected] ~]#
[[email protected] ~]# ps -ef|grep mariadb
root      7261     1  0 23:42 pts/2    00:00:00 /bin/sh ./bin/mysqld_safe --datadir=/var/lib/mariadb --user=u --log-error=/var/log/mariadb/mariadb_err.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mariadb/mariadb.sock --port=3307
mysql     7365  7261  3 23:42 pts/2    00:00:00 /usr/local/mariadb/bin/mysqld --basedir=/usr/local/mariadb --datadir=/var/lib/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=u --log-error=/var/log/mariadb/mariadb_err.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mariadb/mariadb.sock --port=3307
root      7411  7054  0 23:42 pts/2    00:00:00 grep mariadb
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# /usr/local/mariadb/bin/mysql -P 3307
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.8-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> quit

8,设置mysql和mariadb的数据库密码

设置mysql的密码

[[email protected] ~]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password(‘123456‘) where user=‘root‘;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2  Changed: 0  Warnings: 0

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql>

设置mariadb的密码

[[email protected] ~]#
[[email protected] ~]# /usr/local/mariadb/bin/mysql -P 3307
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 10.3.8-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> update user set password=password(‘123456‘) where user=‘root‘;
Query OK, 0 rows affected (0.045 sec)
Rows matched: 2  Changed: 0  Warnings: 0

MariaDB [mysql]> commit;
Query OK, 0 rows affected (0.000 sec)

MariaDB [mysql]> quit

现在设在完了再不能无密码登录了,都需要-p参数指定密码才行

9,开始升级操作

升级之前肯定要先迁移数据

先导出mysql所有库的数据

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# mysqldump -A -uroot -p123456 >all.sql
[[email protected] ~]# 

10,导入mysql说有数据到mariadb中

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# /usr/local/mariadb/bin/mysql -h 127.0.0.1 -P 3307 <all.sql
[[email protected] ~]#
 

11,验证是否导入成功,且mariadb是否正常

由下面可以看出mariadb没有异常,并且mysql的tmp1库也迁移到了mariadb中,1000条数据也都存在

注:我已经事先在mysql中创建量tmp1库,并建立了1个stu表,插入了1000条数据。

[[email protected] ~]# /usr/local/mariadb/bin/mysql -P 3307 -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.3.8-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| tmp1               |
+--------------------+
5 rows in set (0.001 sec)

MariaDB [(none)]> use tmp1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [tmp1]> show tables;
+----------------+
| Tables_in_tmp1 |
+----------------+
| stu            |
+----------------+
1 row in set (0.001 sec)

MariaDB [tmp1]> select count(*) from stu;
+----------+
| count(*) |
+----------+
|     1000 |
+----------+
1 row in set (0.001 sec)

MariaDB [tmp1]> quit

12,建立mysql和mariadb的主从同步,让mariadb实时的同步mysql的数据,直到数据完全一致之后,选择在业务低谷期,例如凌晨进行切换,即分离主从,停止mysql,启用maraidb即可,操作步骤暂时没时间写

原文地址:https://www.cnblogs.com/sonwnja/p/9440472.html

时间: 2024-10-11 05:16:36

mysql升级到mariadb[同一台机器上]的相关文章

解决mysql跟php不在同一台机器上,编译安装php服务报错问题:configure: error: Cannot find MySQL header files under /application/mysql.

在编译安装php服务时报错: configure: error: Cannot find MySQL header files under /application/mysql. Note that the MySQL client library is not bundled anymore! 前边搭建lnmp环境时,是把mysql和php安装在了同一台机器上,编译php的时候,需要通过参数 --with-mysql来指定mysql的安装路径,但在生产环境中,通常php和mysql是不在同一台

shell远程操作另外一台机器上数据

shell远程操作另外一台机器上的数据,有两种方式: 1 .配置免密登陆,2.使用sshpass 当前存在两台虚拟机,ip地址分别为:192.168.3.32 192.168.3.33 一.免密登陆操作另外一台机器 1.生成秘钥 两台机器上都做如下操作,三次输入,直接摁回车 [[email protected] work]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save

如何确定Hadoop守护进程分别会在哪台机器上运行

经过一段时间的配置,Hadoop环境总算运行起来了,但是呢,为何主节点就没有跑tasktracker和datanode进程,slave节点也没有跑secondary进程,Hadoop是如何控制的呢? 经过看权威指南(267页)和跟群里同学讨论,还有自己测试,最终确定: tasktracker和datanode这两个守护进程 —— 只会在conf/slaves文件里指定的那些节点上运行 secondarynamenode 这个守护进程 —— 只会在conf/masters文件里指定的那个节点上运行

如何在一台机器上配置多个git的rsa

如何在一台机器上配置多个git的rsa 问题的提出 很多时候,我们一台机器上要使用多个git库,比如 github, csdn 以及 自己公司的.那么 rsa就要有多份.那么该如何让这些共同存在呢? 原理就是:建立多个不同的rsa 然后 在ssh config中分别不同的配置. 具体步骤 1 建立rsa ssh-keygen -t rsa -C "你的邮箱地址" 执行完这条命令之后, 会弹出如下提示: Enter file in which to save the key (/User

在一台机器上搭建多个redis实例

默认Redis程序安装在/usr/local/redis目录下: 配置文件:/usr/local/redis/redis.conf,该配置文件中配置的端口为默认端口:6379: Redis的启动命令路径:/usr/local/bin/redis-server. 可以指定端口启动多个Redis进程. #/usr/local/bin/redis-server --port 6380 &    #启动6380端口的redis实例. ====================以下每个进程对应一个配置文件(

一台机器上运行多个ActiveMq

由于业务需要一台机器上运行多个ActiveMq,这里主要说一下有什么地方不重复: 1.brokerName名称不能重复 2.端口号不能重复uri = tcp://localhost:50509 3.kahadb路径不能重复 4.管理端口不能重复contextPort = 2019 jmxServiceUrl = service:jmx:rmi:///jndi/rmi://localhost:2019/jmxrmi

在同一台机器上启动多个tomcat服务

一台机器上启动多个tomcat服务应用,能够让我们更好的测试下自己的分布式应用,下面简单介绍下如何在一台机器上开启多个tomcat应用,其实会弄两个,之后的多个都是一样的了 找到电脑上的tomcat安装目录,复制一份,出现两份tomcat,为了区别给复制的一份起一个特别的名称apache-tomcat-6.0.35-8090 进入apache-tomcat-6.0.35-8090目录中,进入conf目录下找到server.xml需要进行多个地方修改 conf目录下修改sever.xml 主要修改

同一台机器上有多个Python版本?

有关Python网站上的官方文档,如何在Linux上的同一台机器上安装和运行多个版本的Python? 我可以找到大量的博客帖子和答案,但我想知道是否有“标准”官方方式这样做? 或者这完全取决于操作系统? 解决方案 我认为它是完全独立的.只需安装它们,然后你就可以使用命令/usr/bin/python2.5和/usr/bin/python2.6.链接/usr/bin/python到您要用作默认值的链接. 无论如何,所有库都在单独的文件夹中(以版本命名). 如果要手动编译版本,请参阅Python源代

LinkedIn的即时消息:在一台机器上支持几十万条长连接

最近我们介绍了LinkedIn的即时通信,最后提到了分型指标和读回复.为了实现这些功能,我们需要有办法通过长连接来把数据从服务器端推送到手机或网页客户端,而不是许多当代应用所采取的标准的请求-响应模式.在这篇文章中会描述在我们收到了消息.分型指标和读回复之后,如何立刻把它们发往客户端. 内容会包含我们是如何使用Play框架和Akka Actor Model来管理长连接.由服务器主动发送事件的.我们也会分享一些在生产环境中我们是如何在服务器上做负载测试,来管理数十万条并发长连接的,还有一些心得.最