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倉庫文件的內容
[root@rabbit ~]# 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安裝的過程已經省略,只給出安裝指令
[root@rabbit ~]# yum -y install mysql-server mysql
3,檢查是否可以啟動mysql並連接
下圖可以看見直接敲mysql指令就進入了數據庫,這時因為剛安裝好之後還沒有設置密碼
[root@rabbit ~]# ls /etc/init.d/mysql*
/etc/init.d/mysqld
[root@rabbit ~]# service mysqld start
正在啟動 mysqld: [確定]
[root@rabbit ~]#
[root@rabbit ~]#
[root@rabbit ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
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> 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/
在瀏覽器裏打開後可能需要你填信息,信息隨便填假信息也可以,但得符合格式,人家讓你填電話你就別傻到填字母就行
下載後進行解壓並安裝
[root@rabbit ~]# ls /home/ting/下載/mariadb-* /home/ting/下載/mariadb-10.3.8.tar.gz [root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]#
[root@rabbit ~]# cd /root [root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# tar -xf mariadb-10.3.8.tar.gz [root@rabbit ~]# [root@rabbit ~]#
編譯安裝之前需要安裝編譯環境
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# yum -y install gcc gcc-c++ cmake bison bison-devel ncurses-devel openssl-devel openssl
開始編譯安裝
[root@rabbit mariadb-10.3.8]# [root@rabbit mariadb-10.3.8]# [root@rabbit 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
[root@rabbit mariadb-10.3.8]# [root@rabbit mariadb-10.3.8]# make
[root@rabbit mariadb-10.3.8]# [root@rabbit mariadb-10.3.8]# make install
5,編寫mariadb的啟動管理腳本
目的是便於啟動或停止mariadb
編寫之前先建立相關目錄和授權
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# mkdir /var/lib/mariadb [root@rabbit ~]# [root@rabbit ~]# mkdir /var/run/mariadb [root@rabbit ~]# [root@rabbit ~]# mkdir /var/log/mariadb [root@rabbit ~]# [root@rabbit ~]# chown mysql.mysql /var/lib/mariadb [root@rabbit ~]# [root@rabbit ~]# chown mysql.mysql /var/run/mariadb [root@rabbit ~]# [root@rabbit ~]# 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/目錄下去
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# cp mariadb /etc/init.d/ [root@rabbit ~]# [root@rabbit ~]# chmod +x /etc/init.d/mariadb [root@rabbit ~]# [root@rabbit ~]#
7,檢查mariadb服務是否可以正常運行並連接
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# ls -l /etc/init.d/mar* -rwxr-xr-x. 1 root root 1303 8月 7 23:39 /etc/init.d/mariadb [root@rabbit ~]# [root@rabbit ~]# 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 ... [root@rabbit ~]# [root@rabbit ~]# 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 [root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# /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的密碼
[root@rabbit ~]# 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的密碼
[root@rabbit ~]# [root@rabbit ~]# /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所有庫的數據
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# mysqldump -A -uroot -p123456 >all.sql [root@rabbit ~]#
10,導入mysql說有數據到mariadb中
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# /usr/local/mariadb/bin/mysql -h 127.0.0.1 -P 3307 <all.sql [root@rabbit ~]#
11,驗證是否導入成功,且mariadb是否正常
由下面可以看出mariadb沒有異常,並且mysql的tmp1庫也遷移到了mariadb中,1000條數據也都存在
註:我已經事先在mysql中創建量tmp1庫,並建立了1個stu表,插入了1000條數據。
[root@rabbit ~]# /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倉庫文件的內容
[root@rabbit ~]# 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安裝的過程已經省略,只給出安裝指令
[root@rabbit ~]# yum -y install mysql-server mysql
3,檢查是否可以啟動mysql並連接
下圖可以看見直接敲mysql指令就進入了數據庫,這時因為剛安裝好之後還沒有設置密碼
[root@rabbit ~]# ls /etc/init.d/mysql*
/etc/init.d/mysqld
[root@rabbit ~]# service mysqld start
正在啟動 mysqld: [確定]
[root@rabbit ~]#
[root@rabbit ~]#
[root@rabbit ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
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> 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/
在瀏覽器裏打開後可能需要你填信息,信息隨便填假信息也可以,但得符合格式,人家讓你填電話你就別傻到填字母就行
下載後進行解壓並安裝
[root@rabbit ~]# ls /home/ting/下載/mariadb-* /home/ting/下載/mariadb-10.3.8.tar.gz [root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]#
[root@rabbit ~]# cd /root [root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# tar -xf mariadb-10.3.8.tar.gz [root@rabbit ~]# [root@rabbit ~]#
編譯安裝之前需要安裝編譯環境
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# yum -y install gcc gcc-c++ cmake bison bison-devel ncurses-devel openssl-devel openssl
開始編譯安裝
[root@rabbit mariadb-10.3.8]# [root@rabbit mariadb-10.3.8]# [root@rabbit 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
[root@rabbit mariadb-10.3.8]# [root@rabbit mariadb-10.3.8]# make
[root@rabbit mariadb-10.3.8]# [root@rabbit mariadb-10.3.8]# make install
5,編寫mariadb的啟動管理腳本
目的是便於啟動或停止mariadb
編寫之前先建立相關目錄和授權
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# mkdir /var/lib/mariadb [root@rabbit ~]# [root@rabbit ~]# mkdir /var/run/mariadb [root@rabbit ~]# [root@rabbit ~]# mkdir /var/log/mariadb [root@rabbit ~]# [root@rabbit ~]# chown mysql.mysql /var/lib/mariadb [root@rabbit ~]# [root@rabbit ~]# chown mysql.mysql /var/run/mariadb [root@rabbit ~]# [root@rabbit ~]# 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/目錄下去
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# cp mariadb /etc/init.d/ [root@rabbit ~]# [root@rabbit ~]# chmod +x /etc/init.d/mariadb [root@rabbit ~]# [root@rabbit ~]#
7,檢查mariadb服務是否可以正常運行並連接
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# ls -l /etc/init.d/mar* -rwxr-xr-x. 1 root root 1303 8月 7 23:39 /etc/init.d/mariadb [root@rabbit ~]# [root@rabbit ~]# 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 ... [root@rabbit ~]# [root@rabbit ~]# 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 [root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# /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的密碼
[root@rabbit ~]# 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的密碼
[root@rabbit ~]# [root@rabbit ~]# /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所有庫的數據
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# mysqldump -A -uroot -p123456 >all.sql [root@rabbit ~]#
10,導入mysql說有數據到mariadb中
[root@rabbit ~]# [root@rabbit ~]# [root@rabbit ~]# /usr/local/mariadb/bin/mysql -h 127.0.0.1 -P 3307 <all.sql [root@rabbit ~]#
11,驗證是否導入成功,且mariadb是否正常
由下面可以看出mariadb沒有異常,並且mysql的tmp1庫也遷移到了mariadb中,1000條數據也都存在
註:我已經事先在mysql中創建量tmp1庫,並建立了1個stu表,插入了1000條數據。
[root@rabbit ~]# /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即可,操作步驟暫時沒時間寫
mysql升級到mariadb[同一臺機器上]