mysql升级

演示以及5.5升级到5.6
当前数据库信息

mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.5.46, for Linux (x86_64) using readline 5.1

Connection id:          2
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.5.46-log Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /data/mysql/mysql.sock
Uptime:                 37 min 18 sec

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| log                |
| mysql              |
| performance_schema |
| test               |
| tpcc               |
+--------------------+
7 rows in set (0.01 sec)

1下载mysql5.6安装包并配置mysql5.6安装包安装路径

5.6安装包
[root@miles mysql5.6.27]# pwd
/usr/local/mysql5.6.27
[root@miles mysql5.6.27]# ll
total 172
drwxr-xr-x.  2 root root    4096 Dec  1 19:20 bin
-rw-r--r--.  1 7161 wheel  17987 Sep 18 22:24 COPYING
drwxr-xr-x.  3 root root    4096 Dec  1 19:20 data
drwxr-xr-x.  2 root root    4096 Dec  1 19:20 docs
drwxr-xr-x.  3 root root    4096 Dec  1 19:20 include
-rw-r--r--.  1 7161 wheel 105656 Sep 18 22:24 INSTALL-BINARY
drwxr-xr-x.  3 root root    4096 Dec  1 19:20 lib
drwxr-xr-x.  4 root root    4096 Dec  1 19:20 man
drwxr-xr-x. 10 root root    4096 Dec  1 19:21 mysql-test
-rw-r--r--.  1 7161 wheel   2496 Sep 18 22:24 README
drwxr-xr-x.  2 root root    4096 Dec  1 19:20 scripts
drwxr-xr-x. 28 root root    4096 Dec  1 19:20 share
drwxr-xr-x.  4 root root    4096 Dec  1 19:20 sql-bench
drwxr-xr-x.  2 root root    4096 Dec  1 19:20 support-files

2关闭mysql5.5的实例,修改部分参数,使用mysql5.6软件启动

[root@miles mysql5.6.27]# ps -ef | grep mysql
root       1474      1  0 19:04 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/miles.pid
mysql      1891   1474  0 19:04 ?        00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/log/error.log --pid-file=/data/mysql/miles.pid --socket=/data/mysql/mysql.sock

[root@miles mysql5.6.27]# mysqladmin -uroot -p --socket=/data/mysql/mysql.sock shutdown

修改参数文件
[root@miles mysql5.6.27]# vi /etc/my.cnf 
把文件中指向5.5的位置指向5.6的

修改环境变量
[root@miles mysql5.6.27]# vi /etc/profile
export MYSQL_HOME=/usr/local/mysql5.6.27
export PATH=$MYSQL_HOME/bin:$PATH

export C_INCLUDE_PATH=$MYSQL_HOME/include

export LIBDIR=/usr/local/lib
export LD_LIBRARY_PATH=/usr/local/lib:$MYSQL_HOME/lib
export LD_RUN_PATH=/usr/local/lib

[root@miles mysql5.6.27]# source /etc/profile

使用5.6启动
[root@miles mysql5.6.27]# /usr/local/mysql5.6.27/bin/mysqld_safe --defaults-file=/etc/my.cnf  &

[root@miles mysql5.6.27]# ps -ef |grep mysql
root       3607   3093  0 20:17 pts/1    00:00:00 /bin/sh /usr/local/mysql5.6.27/bin/mysqld_safe --defaults-file=/etc/my.cnf
mysql      3889   3607 28 20:17 pts/1    00:00:02 /usr/local/mysql5.6.27/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql5.6.27 --datadir=/data/mysql --plugin-dir=/usr/local/mysql5.6.27/lib/plugin --user=mysql --log-error=/data/mysql/log/error.log --pid-file=/data/mysql/mysqld.pid --socket=/data/mysql/mysql.sock

[root@miles mysql5.6.27]# mysql -uroot -p --socket=/data/mysql/mysql.sock
mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.6.27, for linux-glibc2.5 (x86_64) using  EditLine wrapper

Connection id:          1
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.6.27-log MySQL Community Server (GPL)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /data/mysql/mysql.sock
Uptime:                 1 min 34 sec

3执行mysql5.6路径下mysql_upgrade脚本

指令的说明
[root@miles mysql5.6.27]# /usr/local/mysql5.6.27/bin/mysql_upgrade --help
-s, --upgrade-system-tables 
                      Only upgrade the system tables do not try to upgrade the
                      data.

如果数据库数据量较大,不加-s的话升级时间可能较长
[root@miles mysql5.6.27]# /usr/local/mysql5.6.27/bin/mysql_upgrade -uroot -p --socket=/data/mysql/mysql.sock -s

4验证是否成功升级

[root@miles mysql5.6.27]# mysql -uroot -p --socket=/data/mysql/mysql.sock
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| log                |
| mysql              |
| performance_schema |
| test               |
| tpcc               |
+--------------------+
7 rows in set (0.00 sec)

mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.6.27, for linux-glibc2.5 (x86_64) using  EditLine wrapper

Connection id:          7
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.6.27-log MySQL Community Server (GPL)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /data/mysql/mysql.sock
Uptime:                 10 min 47 sec
上一篇:mysql备份策略的制定


下一篇:mysql主从复制部署