公司服务器使用的是5.6版本mysql,然后要升级到5.7,然而公司的mysql是使用rpm包安装的mysql,于是我在网上各种搜索mysql升级,终于在网上找到了一篇文章下面是文章的地址,(我是在参考人家的基础上升级的)
注意: 我的是rpm安装的5.6升级到5.7,使用的是编译方法。如果您的mysql低版本是编译方法升级的话可以用以下链接地址
这是我参考的原文章地址:http://suifu.blog.51cto.com/9167728/1863807?utm_source=tuicool&utm_medium=referral
升级的方法一般有两类:
利用mysqldump来直接导出sql文件,导入到新库中,这种方法是最省事儿的,也是最保险的,缺点的话,也显而易见,大库的mysqldump费时费力。
直接替换掉mysql的安装目录和my.cnf,利用mysql_upgrade
来完成系统表的升级,这种方法需要备份原有的文件,但属于物理拷贝,速度较快。缺点的话,跨版本升级不推荐这么做,比如mysql5.1升级到mysql5.6,mysql5.5升级到mysql5.7等。
我的方法是参考第二种方法升级,用5.7的改掉rpm安装的5.6的mysql文件路径,修改相应的/etc/my.cnf,/etc/init.d/mysql和/etc/init.d/mysqld
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 341458
Server version: 5.6.31-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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 version();
+------------+
| version() |
+------------+
| 5.6.31-log |
+------------+
1 row in set (0.00 sec)
[root@localhost home]# cp /etc/my.cnf /etc/my_56.cnf
[root@localhost home]# tar -zxvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
[root@localhost home]# service mysql stop
[root@localhost home]# mv mysql-5.7.16-linux-glibc2.5-x86_64 /usr/local/mysql
[root@localhost home]# chown -R mysql. /usr/local/mysql
[root@localhost home]# cd /usr/local/mysql/
[root@localhost mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[client]
port=3306
socket=/var/lib/mysql/mysql.sock #你的sock文件目录
default-character-set=utf8
[mysql]
no-auto-rehash
default-character-set=utf8
[mysqld]
port=3306
character-set-server=utf8
socket=/var/lib/mysql/mysql.sock #你的sock文件目录
basedir=/usr/local/mysql
datadir=/var/lib/mysql #你的数据库文件目录
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet=32M
[myisamchk]
key_buffer=16M
sort_buffer_size=16M
read_buffer=8M
write_buffer=8M
[mysqld_safe]
open-files-limit=8192
log-error=/var/lib/mysql/error.log #你的错误日志文件目录
#pid-file=/data/mysql/mysqld.pid #你的pid文件目录,我的没配置
根据自己的情况添加my.cnf配置
3.7、配置编译/etc/init.d/mysqld
#datadir=/usr/local/mysql/data #修改成你的数据库文件目录
datadir=/var/lib/mysql
[root@localhost mysql]# /etc/init.d/msyqld start
[root@localhost support-files]# ps -ef|grep mysql
root 6966 1 0 Dec14 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.pid
mysql 7168 6966 0 Dec14 pts/1 00:00:13 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql/error.log --open-files-limit=8192 --pid-file=/var/lib/mysql/localhost.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root 7270 7244 0 00:27 pts/2 00:00:00 vim mysql.server
root 7287 6165 0 01:49 pts/1 00:00:00 grep mysql
升级成功,然后再升级字典,否则会在错误日志中看到很多错误
[root@localhost mysql]# /usr/local/mysql/bin/mysql_upgrade -uroot -pMANAGER
mysql_upgrade: [Warning] Using a password on the command line interface can be insecure.
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Upgrading the sys schema.
Checking databases.
helei.helei OK
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
—如果升级报错的话,检查自己的my.cnf文件,看其中是否有自己不需要的配置,我的就是里面有多余的配置,注释或删掉就可
- 3.10、重启mysql
[root@localhost mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
升级后的版本
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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 version();
+-----------+
| version() |
+-----------+
| 5.7.16 |
+-----------+
1 row in set (0.00 sec)
mysql>
[root@localhost ~]# whereis mysql
mysql: /usr/bin/mysql /usr/local/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
mysql> grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
mysql> flush privileges;