环境:RHEL 6
mysql旧版本:mysql-5.5.28
mysql新版本:mysql-5.6.26
安装方式:源码编译
不习惯用rpm包来安装mysql,所以此处仍然使用用源码安装编译mysql。
若为rpm包安装,操作过程大体一致,当然路径和安装方法有出入。
因为是实验环境,首先安装mysql5.5。
basedir : /home/sano1y/mysql5.5
datadir : /home/sano1y/mysql5.5/data
socket : /tmp/mysql.sock
配置文件路径 : /home/sano1y/.my.cnf
此处操作系统用户名为sano1y,下同。
安装过程略。
安装完后配一下用户环境变量
-
vi ~/.bash_profile
-
-
添加 export PATH=$PATH:/home/sano1y/mysql5.5/bin
-
-
source ~/.bash_profile
将默认配置文件放到~/.my.cnf
-
cp ~/mysql5.5/support-files/my-medium.cnf ~/.my.cnf
先启动服务,修改一下初始密码并确认版本:
-
-
-
[sano1y@localhost ~]$ mysql -uroot -p
-
Enter password:
-
Welcome to the MySQL monitor. Commands end with ; or \g.
-
Your MySQL connection id is 5
-
Server version: 5.5.28-log Source distribution
-
-
Copyright (c) 2000, 2012, 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>
-
mysql> set password=password('root');
-
Query OK, 0 rows affected (0.00 sec)
-
-
mysql>
-
mysql> flush privileges;
-
Query OK, 0 rows affected (0.00 sec)
因为5.5、5.6版本的密码均为空,所以先指定一个密码,后面将会用到。
① 停止旧版本服务
-
[sano1y@localhost bin]$ mysqladmin -uroot -p shutdown
-
Enter password:
-
151125 00:13:35 mysqld_safe mysqld from pid file /home/sano1y/mysql5.5/data/localhost.localdomain.pid ended
-
[1]+ Done ./mysqld_safe
-
-
[sano1y@localhost mysql5.6]$ ps -ef | grep mysql
-
sano1y 20590 19687 0 02:00 pts/2 00:00:00 grep mysql
-
② 备份数据库
备份数据文件,略。
同时备份参数文件。
-
cp ~/.my.cnf ~/.my.cnf.bk
③ 安装新版本
同样通过cmake make make install来编译安装 mysql5.6,并初始化
并修改用户环境变量。
-
vi ~/.bash_profile
-
export PATH=$PATH:/home/sano1y/mysql5.6/bin
-
source ~/.bash_profile
将默认5.6的配置文件修改掉(禁用)
-
mv ~/mysql5.6/my.cnf ~/mysql5.6/my.cnf.default
将对应参数修改为新的。
-
vi ~/.my.cnf
-
[mysqld]
-
basedir=/home/sano1y/mysql5.6
-
datadir=/home/sano1y/mysql5.5/data
-
pid-file=/home/sano1y/mysql5.5/sAno1y.pid
④ 启动新版本服务
此时mysql服务器会找到 ~/.my.cnf这个配置文件,并启用。
⑤ 检查升级的表
此时做mysql_upgrade进行检查
-
mysql_upgrade -uroot -p --force
然后是mysqlcheck
进入mysql client检查:
此时密码仍然是mysql5.5的,因为启动时,是在/home/sano1y/mysql5.5/data/中的mysql.user中校验。
-
[sano1y@localhost bin]$ mysql -uroot -p
-
Welcome to the MySQL monitor. Commands end with ; or \g.
-
Your MySQL connection id is 26
-
Server version: 5.6.26-log Source distribution
-
-
Copyright (c) 2000, 2012, 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> select @@datadir;
-
+-----------------------------+
-
| @@datadir |
-
+-----------------------------+
-
| /home/sano1y/mysql5.5/data/ |
-
+-----------------------------+
-
1 row in set (0.00 sec)
顺便可以删一下mysql5.5目录里的其他目录:
-
[sano1y@localhost ~]$ cd mysql5.5
-
[sano1y@localhost mysql5.5]$ ls
-
bin data include lib mysql-test scripts sql-bench sAno1y.pid
-
COPYING docs INSTALL-BINARY man README share support-files
-
[sano1y@localhost mysql5.5]$ rm -rf bin/ include/ lib/ mysql-test/ scripts/ sql-bench/ COPYING docs/ INSTALL-BINARY man/ README share/ support-files/
-
[sano1y@localhost mysql5.5]$
-
[sano1y@localhost mysql5.5]$ ls
-
data sAno1y.pid
总结升级过程:
① 停止旧版本服务 → ② 备份数据库 → ③ 安装新版本 → ④ 启动新版本服务 → ⑤ 检查升级的表
作者公众号(持续更新)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29773961/viewspace-1846662/
,如需转载,请注明出处,否则将追究法律责任。