CDH中的MySQL升级(RPM包方式)

CDH中的MySQL升级(RPM包方式)

1.下载官网的5.7中最新的版本,地址:MySQL 5.7.41 rpm下载地址
CDH中的MySQL升级(RPM包方式)_第1张图片

在这里插入图片描述

2.解压下载的tar包:tar -xvf mysql-5.7.41-1.el7.x86_64.rpm-bundle.tar

CDH中的MySQL升级(RPM包方式)_第2张图片

3.备份数据库
3.1 先停止MySQL服务:systemctl stop mysqld
3.2 备份数据:升级MySQL通常不会丢失数据,但保险起见,我们需要做这一步。输入命令

mysqldump -u root -h xxx -P 3306 -p --all-databases > databases.sql

备份配置文件:

cp /etc/my.cnf /etc/my.cnf.bak

4.卸载旧版本 MySQL

[root@cdh01 mysql]# yum remove mysql mysql-*
Loaded plugins: security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.i686 0:5.1.73-7.el6 will be erased
---> Package mysql-libs.i686 0:5.1.73-7.el6 will be erased
--> Processing Dependency: libmysqlclient.so.16 for package: 2:postfix-2.6.6-6.el6_7.1.i686
--> Processing Dependency: libmysqlclient.so.16 for package: perl-DBD-MySQL-4.013-3.el6.i686
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16) for package: 2:postfix-2.6.6-6.el6_7.1.i686
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16) for package: perl-DBD-MySQL-4.013-3.el6.i686
--> Processing Dependency: mysql-libs for package: 2:postfix-2.6.6-6.el6_7.1.i686
---> Package mysql-server.i686 0:5.1.73-7.el6 will be erased
--> Running transaction check
---> Package perl-DBD-MySQL.i686 0:4.013-3.el6 will be erased
---> Package postfix.i686 2:2.6.6-6.el6_7.1 will be erased
--> Processing Dependency: /usr/sbin/sendmail for package: cronie-1.4.4-16.el6_8.2.i686
--> Processing Dependency: /usr/sbin/sendmail for package: redhat-lsb-core-4.0-7.el6.centos.i686
--> Running transaction check
---> Package cronie.i686 0:1.4.4-16.el6_8.2 will be erased
--> Processing Dependency: cronie = 1.4.4-16.el6_8.2 for package: cronie-anacron-1.4.4-16.el6_8.2.i686
---> Package redhat-lsb-core.i686 0:4.0-7.el6.centos will be erased
--> Running transaction check
---> Package cronie-anacron.i686 0:1.4.4-16.el6_8.2 will be erased
--> Processing Dependency: /etc/cron.d for package: crontabs-1.10-33.el6.noarch
--> Processing Dependency: /etc/cron.d for package: sysstat-9.0.4-31.el6.i686
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package crontabs.noarch 0:1.10-33.el6 will be erased
---> Package sysstat.i686 0:9.0.4-31.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================================
 Package                                     Arch                               Version                                       Repository                                                          Size
=======================================================================================================================================================================================================
Removing:
 mysql                                       i686                               5.1.73-7.el6                                  @base                                                              2.3 M
 mysql-libs                                  i686                               5.1.73-7.el6                                  @base                                                              3.9 M
 mysql-server                                i686                               5.1.73-7.el6                                  @base                                                               24 M
Removing for dependencies:
 cronie                                      i686                               1.4.4-16.el6_8.2                              @updates                                                           169 k
 cronie-anacron                              i686                               1.4.4-16.el6_8.2                              @updates                                                            38 k
 crontabs                                    noarch                             1.10-33.el6                                   @anaconda-CentOS-201311291201.i386/6.5                             2.4 k
 perl-DBD-MySQL                              i686                               4.013-3.el6                                   @base                                                              341 k
 postfix                                     i686                               2:2.6.6-6.el6_7.1                             @base                                                              9.3 M
 redhat-lsb-core                             i686                               4.0-7.el6.centos                              @anaconda-CentOS-201311291201.i386/6.5                              22 k
 sysstat                                     i686                               9.0.4-31.el6                                  @base                                                              804 k

Transaction Summary
=======================================================================================================================================================================================================
Remove       10 Package(s)

Installed size: 41 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : mysql-server-5.1.73-7.el6.i686                                                                                                                                                     1/10 
warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
  Erasing    : redhat-lsb-core-4.0-7.el6.centos.i686                                                                                                                                              2/10 
/var/tmp/rpm-tmp.Y5QGjy: line 1: lsb_release: command not found
  Erasing    : mysql-5.1.73-7.el6.i686                                                                                                                                                            3/10 
  Erasing    : perl-DBD-MySQL-4.013-3.el6.i686                                                                                                                                                    4/10 
  Erasing    : sysstat-9.0.4-31.el6.i686                                                                                                                                                          5/10 
  Erasing    : crontabs-1.10-33.el6.noarch                                                                                                                                                        6/10 
  Erasing    : cronie-anacron-1.4.4-16.el6_8.2.i686                                                                                                                                               7/10 
  Erasing    : cronie-1.4.4-16.el6_8.2.i686                                                                                                                                                       8/10 
  Erasing    : 2:postfix-2.6.6-6.el6_7.1.i686                                                                                                                                                     9/10 
  Erasing    : mysql-libs-5.1.73-7.el6.i686                                                                                                                                                      10/10 
  Verifying  : redhat-lsb-core-4.0-7.el6.centos.i686                                                                                                                                              1/10 
  Verifying  : perl-DBD-MySQL-4.013-3.el6.i686                                                                                                                                                    2/10 
  Verifying  : mysql-server-5.1.73-7.el6.i686                                                                                                                                                     3/10 
  Verifying  : crontabs-1.10-33.el6.noarch                                                                                                                                                        4/10 
  Verifying  : sysstat-9.0.4-31.el6.i686                                                                                                                                                          5/10 
  Verifying  : cronie-anacron-1.4.4-16.el6_8.2.i686                                                                                                                                               6/10 
  Verifying  : cronie-1.4.4-16.el6_8.2.i686                                                                                                                                                       7/10 
  Verifying  : mysql-libs-5.1.73-7.el6.i686                                                                                                                                                       8/10 
  Verifying  : mysql-5.1.73-7.el6.i686                                                                                                                                                            9/10 
  Verifying  : 2:postfix-2.6.6-6.el6_7.1.i686                                                                                                                                                    10/10 

Removed:
  mysql.i686 0:5.1.73-7.el6                                     mysql-libs.i686 0:5.1.73-7.el6                                     mysql-server.i686 0:5.1.73-7.el6                                    

Dependency Removed:
  cronie.i686 0:1.4.4-16.el6_8.2              cronie-anacron.i686 0:1.4.4-16.el6_8.2     crontabs.noarch 0:1.10-33.el6     perl-DBD-MySQL.i686 0:4.013-3.el6     postfix.i686 2:2.6.6-6.el6_7.1    
  redhat-lsb-core.i686 0:4.0-7.el6.centos     sysstat.i686 0:9.0.4-31.el6               

Complete!

至此MySQL就卸载完成了,我们可以检查一下系统中是否还有 MySQL 相关内容没有删除干净

[root@cdh01 mysql]# yum list installed | grep mysql
[root@cdh01 mysql]# 

上面的情况是没有未删除部分,如果有的话可通过下面的命令删除:

yum remove mysql 进行卸载(这里的mysql就是上面命令的运行结果)

5.安装新版本MySQL

依次执行以下6个命令进行安装

rpm -ivh mysql-community-common-5.7.41-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-5.7.41-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-devel-5.7.41-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-5.7.41-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm --nodeps --force

查看版本:

[root@cdh01 mysql]#  mysql -V
mysql  Ver 14.14 Distrib 5.7.41, for Linux (x86_64) using  EditLine wrapper

6.启动MySQL:systemctl start mysqld
这里网上有说可能会失败,如果失败的话,先初始化一下:mysqld --initialize
如果遇到下面的错误:

2017-01-06T14:53:08.889803Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-01-06T14:53:08.892190Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2017-01-06T14:53:08.892475Z 0 [ERROR] Aborting

可以运行以下命令【无需再执行 mysqld --initialize】:

[root@cdh01 mysql]# rm -rf /var/lib/mysql
[root@cdh01 mysql]# systemctl start mysqld 

安装成功后,首先将数据库设置成无密码状态,先恢复配置文件
cp /etc/my.cnf.bak /etc/my.cnf

修改配置

vi /etc/my.cnf 

添加 skip-grant-tables 可保证为无密码状态

CDH中的MySQL升级(RPM包方式)_第3张图片

重启mysql服务器,使配置生效:systemctl restart mysqld

进入数据库,mysql -u root -p 按enter 键进入,使用mysql数据库

CDH中的MySQL升级(RPM包方式)_第4张图片
修改mysql的登录密码为:123456

update user set authentication_string=password("123456") where user='root';

CDH中的MySQL升级(RPM包方式)_第5张图片
如果有报错或者后面使用密码登录有下面的报错的话:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

就执行以下命令:

mysql> set global validate_password_policy =0;
Query OK, 0 rows affected (0.04 sec)

mysql> set global validate_password_length = 6;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;

7.恢复备份的数据

mysql -u root -h xxx -P 3306 -p < databases.sql

你可能感兴趣的:(mysql,数据库,CDH)