---恢复内容开始---
操作系统: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