• ADADADADAD

    MySQL升级从5.1.71到5.7.17[ mysql数据库 ]

    mysql数据库 时间:2024-12-24 19:12:29

    作者:文/会员上传

    简介:

    最近系统漏洞扫描,扫出来很多MySQL的漏洞,没有什么好的办法,先升级到最新版本。在梳理MySQL数据库信息时发现有一套zabbix用的MySQL版本是5.1.71的,现在的最新版本是5.7.17,版本

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    最近系统漏洞扫描,扫出来很多MySQL的漏洞,没有什么好的办法,先升级到最新版本。在梳理MySQL数据库信息时发现有一套zabbix用的MySQL版本是5.1.71的,现在的最新版本是5.7.17,版本跨越的太大了,不知道直接升级是否可行。库的数据量大概15G,于是就想先备份,备份完后用mysql_upgrade做升级。如果实在不行就再新创建一套库把数据导进去。

    下面是在虚拟机上测试的升级步骤,中间也遇到了一些问题,不过好在最后还是升级成功了,说明这条路还是可行了。

    操作系统版本RHEL 6.7 旧的MySQL版本5.1.71,新的MySQL版本5.7.17。

    1、查看旧的MySQL版本,并创建测试数据库和测试表

    mysql>selectversion();+------------------+|version()|+------------------+|5.1.71-community|+------------------+mysql>createdatabasezx;QueryOK,1rowaffected(0.00sec)mysql>showdatabases;+--------------------+|Database|+--------------------+|information_schema||mysql||test||zx|+--------------------+4rowsinset(0.00sec)mysql>usezx;Databasechangedmysql>createtabletest_upgrade(idint);QueryOK,0rowsaffected(0.07sec)......mysql>selectcount(*)fromtest_upgrade;+----------+|count(*)|+----------+|33554432|+----------+1rowinset(0.00sec)

    现在test_upgrade表里有33554432条数据。

    2、停止旧MySQL,并备份数据

    [root@rhel6mysql]#servicemysqlstopShuttingdownMySQL..SUCCESS!#这里直接用cp备份数据[root@rhel6lib]#cp-Rmysqlmysql_bak[root@rhel6lib]#du-skmysql*250880mysql250880mysql_bak

    3、安装新Msql软件,这里下载的是编译好的解压就可以使用

    [root@rhel6~]#tar-zxvfmysql-5.7.17-linux-glibc2.5-x86_64.tar.gz#解压完后移动到/opt目录下[root@rhel6~]#mvmysql-5.7.17-linux-glibc2.5-x86_64mysql-5.7.17[root@rhel6~]#mvmysql-5.7.17/opt[root@rhel6~]#cd/opt[root@rhel6opt]#chown-Rmysql:mysqlmysql-5.7.17/[root@rhel6opt]#lltotal4drwxr-xr-x.9mysqlmysql4096Mar2221:07mysql-5.7.17

    4、修改my.cnf

    主要修改basedir参数:

    [root@rhel6opt]#vi/etc/my.cnfbasedir=/opt/mysql-5.7.17

    5、启动新MySQL

    [root@rhel6mysql-5.7.17]#./bin/mysqld_safe&

    1)启动报错1:

    2017-03-22T13:12:39.131998Z0[ERROR]InnoDB:TheAuto-extendinginnodb_systemdatafile'./ibdata1'isofadifferentsize640pages(roundeddowntoMB)thanspecifiedinthe.cnffile:initial768pages,max0(relevantifnon-zero)pages!2017-03-22T13:12:39.132028Z0[ERROR]InnoDB:PlugininitializationabortedwitherrorGenericerror2017-03-22T13:12:39.733953Z0[ERROR]Plugin'InnoDB'initfunctionreturnederror.2017-03-22T13:12:39.733986Z0[ERROR]Plugin'InnoDB'registrationasaSTORAGEENGINEfailed.2017-03-22T13:12:39.733994Z0[ERROR]Failedtoinitializeplugins.2017-03-22T13:12:39.734000Z0[ERROR]Aborting

    解决方法在my.cnf中的[mysqld]部分添加如下参数

    innodb_data_file_path=ibdata1:10M:autoextend

    再次启动

    2)启动报错2:

    2017-03-22T13:16:03.374717Z0[ERROR]unknownoption'--skip-locking'2017-03-22T13:16:03.374735Z0[ERROR]Aborting

    解决方法从my.cnf中注释掉相关参数skip-locking

    再次启动

    3)启动报错3:

    2017-03-22T13:18:20.278752Z0[ERROR]Fatalerror:mysql.usertableisdamaged.Pleaserunmysql_upgrade.2017-03-22T13:18:20.278954Z0[ERROR]Aborting

    5.7无法读取5.1的mysql.user表,解决方法使用--skip-grant-tables参数跳过授权验证

    再次启动

    [root@rhel6mysql-5.7.17]#./bin/mysqld_safe--skip-grant-tables&

    启动成功

    2017-03-22T13:20:23.919677Z0[Note]./bin/mysqld:readyforconnections.Version:'5.7.17'socket:'/var/lib/mysql/mysql.sock'port:3306MySQLCommunityServer(GPL)

    6、执行升级

    [root@rhel6mysql-5.7.17]#./bin/mysql_upgrade-urootCheckingifupdateisneeded.Checkingserverversion.RunningqueriestoupgradeMySQLserver.Checkingsystemdatabase.mysql.columns_privOKmysql.dbOKmysql.engine_costOKmysql.eventOKmysql.funcOKmysql.general_logOKmysql.gtid_executedOKmysql.help_categoryOKmysql.help_keywordOKmysql.help_relationOKmysql.help_topicOKmysql.hostOKmysql.innodb_index_statsOKmysql.innodb_table_statsOKmysql.ndb_binlog_indexOKmysql.pluginOKmysql.procOKmysql.procs_privOKmysql.proxies_privOKmysql.server_costOKmysql.serversOKmysql.slave_master_infoOKmysql.slave_relay_log_infoOKmysql.slave_worker_infoOKmysql.slow_logOKmysql.tables_privOKmysql.time_zoneOKmysql.time_zone_leap_secondOKmysql.time_zone_nameOKmysql.time_zone_transitionOKmysql.time_zone_transition_typeOKmysql.userOKUpgradingthesysschema.Checkingdatabases.sys.sys_configOKzx.test_upgradeOKUpgradeprocesscompletedsuccessfully.Checkingifupdateisneeded.

    7、重启MySQL,并验证

    [root@rhel6mysql-5.7.17]#./bin/mysqladmin-uroot-pshutdown[root@rhel6mysql-5.7.17]#./bin/mysqld_safe&mysql>selectversion();+-----------+|version()|+-----------+|5.7.17|+-----------+1rowinset(0.00sec)mysql>showdatabases;+--------------------+|Database|+--------------------+|information_schema||mysql||performance_schema||sys||test||zx|+--------------------+6rowsinset(0.00sec)mysql>selectcount(*)fromzx.test_upgrade;+----------+|count(*)|+----------+|33554432|+----------+1rowinset(0.01sec)

    验证通过后,删除旧版本的MySQL软件。


    MySQL升级从5.1.71到5.7.17.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载