欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux下升级mysql5.6为5.7详细步骤

程序员文章站 2024-03-20 23:11:04
...

查看已安装mysql

查看本机安装过的mysql,我的为mysql5.6.43版本,停止mysql。

[root@iZwz94664y88ud9aroa5veZ ~]# rpm -qa|grep -i mysql
mysql-community-release-el6-5.noarch
mysql-community-libs-5.6.43-2.el6.x86_64
php-mysql-5.4.16-46.el7.x86_64
mysql-community-client-5.6.43-2.el6.x86_64
mysql-community-server-5.6.43-2.el6.x86_64
zabbix-web-mysql-3.0.25-1.el7.noarch
mysql-community-common-5.6.43-2.el6.x86_64
opensips-mysql-1.10.5-4.el7.x86_64
zabbix-server-mysql-3.0.25-1.el7.x86_64

[root@iZwz94664y88ud9aroa5veZ ~]# 
[root@iZwz94664y88ud9aroa5veZ ~]# systemctl stop mysqld

删除本机的mysql

[root@iZwz94664y88ud9aroa5veZ ~]# 
[root@iZwz94664y88ud9aroa5veZ ~]# ps -ef|grep mysql
polkitd  11943 11909  0 17:37 ?        00:00:00 mysqld
root     12190 11067  0 17:44 pts/0    00:00:00 grep --color=auto mysql
[root@iZwz94664y88ud9aroa5veZ ~]# 
[root@iZwz94664y88ud9aroa5veZ ~]# yum remove mysql*
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.43-2.el6 will be erased
---> Package mysql-community-common.x86_64 0:5.6.43-2.el6 will be erased
---> Package mysql-community-libs.x86_64 0:5.6.43-2.el6 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: opensips-mysql-1.10.5-4.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: php-mysql-5.4.16-46.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: zabbix-server-mysql-3.0.25-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: opensips-mysql-1.10.5-4.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: php-mysql-5.4.16-46.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: zabbix-server-mysql-3.0.25-1.el7.x86_64
---> Package mysql-community-release.noarch 0:el6-5 will be erased
---> Package mysql-community-server.x86_64 0:5.6.43-2.el6 will be erased
--> Running transaction check
---> Package opensips-mysql.x86_64 0:1.10.5-4.el7 will be erased
---> Package php-mysql.x86_64 0:5.4.16-46.el7 will be erased
--> Processing Dependency: php-mysql for package: zabbix-web-mysql-3.0.25-1.el7.noarch
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
---> Package zabbix-server-mysql.x86_64 0:3.0.25-1.el7 will be erased
--> Running transaction check
---> Package zabbix-web-mysql.noarch 0:3.0.25-1.el7 will be erased
--> Processing Dependency: zabbix-web-database = 3.0.25-1.el7 for package: zabbix-web-3.0.25-1.el7.noarch
--> Running transaction check
---> Package zabbix-web.noarch 0:3.0.25-1.el7 will be erased
--> Processing Dependency: /usr/sbin/sendmail for package: redhat-lsb-core-4.1-27.el7.centos.1.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                             Arch                               Version                                           Repository                                      Size
===============================================================================================================================================================================================
Removing:
 mysql-community-client                              x86_64                             5.6.43-2.el6                                      @mysql56-community                              83 M
 mysql-community-common                              x86_64                             5.6.43-2.el6                                      @mysql56-community                             2.1 M
 mysql-community-libs                                x86_64                             5.6.43-2.el6                                      @mysql56-community                             8.6 M
 mysql-community-release                             noarch                             el6-5                                             installed                                      4.3 k
 mysql-community-server                              x86_64                             5.6.43-2.el6                                      @mysql56-community                             242 M
Removing for dependencies:
 opensips-mysql                                      x86_64                             1.10.5-4.el7                                      @epel                                          114 k
 php-mysql                                           x86_64                             5.4.16-46.el7                                     @base                                          232 k
 postfix                                             x86_64                             2:2.10.1-6.el7                                    @anaconda                                       12 M
 redhat-lsb-core                                     x86_64                             4.1-27.el7.centos.1                               @base                                           45 k
 zabbix-server-mysql                                 x86_64                             3.0.25-1.el7                                      @zabbix                                        3.9 M
 zabbix-web                                          noarch                             3.0.25-1.el7                                      @zabbix                                         13 M
 zabbix-web-mysql                                    noarch                             3.0.25-1.el7                                      @zabbix                                        0.0  

Transaction Summary
===============================================================================================================================================================================================
Remove  5 Packages (+7 Dependent packages)

Installed size: 366 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : mysql-community-server-5.6.43-2.el6.x86_64                                                                                                                                 1/12 
  Erasing    : zabbix-web-mysql-3.0.25-1.el7.noarch                                                                                                                                       2/12 
  Erasing    : zabbix-web-3.0.25-1.el7.noarch                                                                                                                                             3/12 
warning: /etc/httpd/conf.d/zabbix.conf saved as /etc/httpd/conf.d/zabbix.conf.rpmsave
  Erasing    : php-mysql-5.4.16-46.el7.x86_64                                                                                                                                             4/12 
  Erasing    : redhat-lsb-core-4.1-27.el7.centos.1.x86_64                                                                                                                                 5/12 
  Erasing    : 2:postfix-2.10.1-6.el7.x86_64                                                                                                                                              6/12 
  Erasing    : mysql-community-client-5.6.43-2.el6.x86_64                                                                                                                                 7/12 
  Erasing    : zabbix-server-mysql-3.0.25-1.el7.x86_64                                                                                                                                    8/12 
warning: /etc/zabbix/zabbix_server.conf saved as /etc/zabbix/zabbix_server.conf.rpmsave
  Erasing    : opensips-mysql-1.10.5-4.el7.x86_64                                                                                                                                         9/12 
  Erasing    : mysql-community-release-el6-5.noarch                                                                                                                                      10/12 
  Erasing    : mysql-community-libs-5.6.43-2.el6.x86_64                                                                                                                                  11/12 
  Erasing    : mysql-community-common-5.6.43-2.el6.x86_64                                                                                                                                12/12 
  Verifying  : zabbix-web-3.0.25-1.el7.noarch                                                                                                                                             1/12 
  Verifying  : opensips-mysql-1.10.5-4.el7.x86_64                                                                                                                                         2/12 
  Verifying  : mysql-community-libs-5.6.43-2.el6.x86_64                                                                                                                                   3/12 
  Verifying  : mysql-community-client-5.6.43-2.el6.x86_64                                                                                                                                 4/12 
  Verifying  : php-mysql-5.4.16-46.el7.x86_64                                                                                                                                             5/12 
  Verifying  : mysql-community-server-5.6.43-2.el6.x86_64                                                                                                                                 6/12 
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                                                                                                                              7/12 
  Verifying  : redhat-lsb-core-4.1-27.el7.centos.1.x86_64                                                                                                                                 8/12 
  Verifying  : zabbix-web-mysql-3.0.25-1.el7.noarch                                                                                                                                       9/12 
  Verifying  : mysql-community-common-5.6.43-2.el6.x86_64                                                                                                                                10/12 
  Verifying  : mysql-community-release-el6-5.noarch                                                                                                                                      11/12 
  Verifying  : zabbix-server-mysql-3.0.25-1.el7.x86_64                                                                                                                                   12/12 

Removed:
  mysql-community-client.x86_64 0:5.6.43-2.el6     mysql-community-common.x86_64 0:5.6.43-2.el6     mysql-community-libs.x86_64 0:5.6.43-2.el6     mysql-community-release.noarch 0:el6-5    
  mysql-community-server.x86_64 0:5.6.43-2.el6    

Dependency Removed:
  opensips-mysql.x86_64 0:1.10.5-4.el7             php-mysql.x86_64 0:5.4.16-46.el7        postfix.x86_64 2:2.10.1-6.el7                 redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1       
  zabbix-server-mysql.x86_64 0:3.0.25-1.el7        zabbix-web.noarch 0:3.0.25-1.el7        zabbix-web-mysql.noarch 0:3.0.25-1.el7       

Complete!

删除遗留mysql文件

检查遗留的mysql文件,删除/usr/share、/var/lib这些路径下的mysql。

[root@iZwz94664y88ud9aroa5veZ ~]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/var/lib/docker/overlay2/1790d666c52b7af5b2b4d0ad2734d82e5dcfde6e3f2e72f5f4ca4425103793e3/diff/etc/mysql
/var/lib/docker/overlay2/1790d666c52b7af5b2b4d0ad2734d82e5dcfde6e3f2e72f5f4ca4425103793e3/diff/usr/include/mysql
/var/lib/docker/overlay2/1790d666c52b7af5b2b4d0ad2734d82e5dcfde6e3f2e72f5f4ca4425103793e3/diff/usr/include/mariadb/server/mysql
/var/lib/docker/overlay2/1790d666c52b7af5b2b4d0ad2734d82e5dcfde6e3f2e72f5f4ca4425103793e3/diff/usr/include/mariadb/mysql
/var/lib/docker/overlay2/668833cf4908d524f1de024d2a73fe131bf00815efaf73bda776f66f02d7cdb9/merged/var/log/mysql
/var/lib/docker/overlay2/668833cf4908d524f1de024d2a73fe131bf00815efaf73bda776f66f02d7cdb9/merged/var/lib/mysql
/var/lib/docker/overlay2/668833cf4908d524f1de024d2a73fe131bf00815efaf73bda776f66f02d7cdb9/merged/etc/init.d/mysql
/var/lib/docker/overlay2/668833cf4908d524f1de024d2a73fe131bf00815efaf73bda776f66f02d7cdb9/merged/etc/mysql
/var/lib/docker/overlay2/668833cf4908d524f1de024d2a73fe131bf00815efaf73bda776f66f02d7cdb9/merged/usr/share/mysql
/var/lib/docker/overlay2/668833cf4908d524f1de024d2a73fe131bf00815efaf73bda776f66f02d7cdb9/merged/usr/bin/mysql
/var/lib/docker/overlay2/668833cf4908d524f1de024d2a73fe131bf00815efaf73bda776f66f02d7cdb9/merged/usr/lib/mysql
/var/lib/docker/overlay2/b5b3e15ea361b24df8bc4b257809511d95f1b374b7040e1307a0fb8fa78fa6da/diff/var/log/mysql
/var/lib/docker/overlay2/b5b3e15ea361b24df8bc4b257809511d95f1b374b7040e1307a0fb8fa78fa6da/diff/var/lib/mysql
/var/lib/docker/overlay2/b5b3e15ea361b24df8bc4b257809511d95f1b374b7040e1307a0fb8fa78fa6da/diff/etc/mysql
/var/lib/docker/overlay2/b5b3e15ea361b24df8bc4b257809511d95f1b374b7040e1307a0fb8fa78fa6da/diff/etc/init.d/mysql
/var/lib/docker/overlay2/b5b3e15ea361b24df8bc4b257809511d95f1b374b7040e1307a0fb8fa78fa6da/diff/usr/share/mysql
/var/lib/docker/overlay2/b5b3e15ea361b24df8bc4b257809511d95f1b374b7040e1307a0fb8fa78fa6da/diff/usr/bin/mysql
/var/lib/docker/overlay2/b5b3e15ea361b24df8bc4b257809511d95f1b374b7040e1307a0fb8fa78fa6da/diff/usr/lib/mysql
/etc/selinux/targeted/active/modules/100/mysql
/usr/share/mysql
/usr/mysql
/usr/mysql/data/mysql
/usr/local/lib64/opensips/opensipsctl/mysql
/usr/src/opensips-2.4.3/obsolete_modules/pdt/scripts/mysql
/usr/src/opensips-2.4.3/scripts/mysql
[root@iZwz94664y88ud9aroa5veZ ~]# ps -ef | grep -i mysql
polkitd  11943 11909  0 17:37 ?        00:00:00 mysqld
root     12282 11067  0 17:46 pts/0    00:00:00 grep --color=auto -i mysql
[root@iZwz94664y88ud9aroa5veZ ~]# rm -rf /var/lib/mysql*
[root@iZwz94664y88ud9aroa5veZ ~]# rm -rf /usr/share/mysql*
[root@iZwz94664y88ud9aroa5veZ ~]# 

安装mysql5.7

[root@iZwz94664y88ud9aroa5veZ ~]# rpm  -ivh https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
Retrieving https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-10 ################################# [100%]
[root@iZwz94664y88ud9aroa5veZ ~]# 
[root@iZwz94664y88ud9aroa5veZ ~]# yum -y install mysql-community-server
Loaded plugins: fastestmirror
base                                                                                                                                                                    | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                        | 3.5 kB  00:00:00     
epel                                                                                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                                                                                  | 2.9 kB  00:00:00     
mysql-connectors-community                                                                                                                                              | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                                                   | 2.5 kB  00:00:00     
mysql57-community                                                                                                                                                       | 2.5 kB  00:00:00     
updates                                                                                                                                                                 | 2.9 kB  00:00:00     
zabbix-non-supported                                                                                                                                                    |  951 B  00:00:00     
(1/5): epel/x86_64/updateinfo                                                                                                                                           | 1.0 MB  00:00:00     
(2/5): epel/x86_64/primary_db                                                                                                                                           | 6.7 MB  00:00:00     
(3/5): mysql-tools-community/x86_64/primary_db                                                                                                                          |  69 kB  00:00:01     
(4/5): mysql-connectors-community/x86_64/primary_db                                                                                                                     |  53 kB  00:00:01     
(5/5): mysql57-community/x86_64/primary_db                                                                                                                              | 198 kB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.29-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.29-1.el7 for package: mysql-community-server-5.7.29-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.29-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.29-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.29-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.29-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.29-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                              Arch                                 Version                                       Repository                                       Size
===============================================================================================================================================================================================
Installing:
 mysql-community-server                               x86_64                               5.7.29-1.el7                                  mysql57-community                               175 M
Installing for dependencies:
 mysql-community-client                               x86_64                               5.7.29-1.el7                                  mysql57-community                                26 M
 mysql-community-common                               x86_64                               5.7.29-1.el7                                  mysql57-community                               311 k
 mysql-community-libs                                 x86_64                               5.7.29-1.el7                                  mysql57-community                               2.5 M

Transaction Summary
===============================================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 204 M
Installed size: 881 M
Downloading packages:
(1/4): mysql-community-common-5.7.29-1.el7.x86_64.rpm                                                                                                                   | 311 kB  00:00:01     
(2/4): mysql-community-libs-5.7.29-1.el7.x86_64.rpm                                                                                                                     | 2.5 MB  00:00:01     
(3/4): mysql-community-client-5.7.29-1.el7.x86_64.rpm                                                                                                                   |  26 MB  00:00:07     
(4/4): mysql-community-server-5.7.29-1.el7.x86_64.rpm                                                                                                                   | 175 MB  00:02:23     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                          1.4 MB/s | 204 MB  00:02:26     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : mysql-community-common-5.7.29-1.el7.x86_64                                                                                                                                  1/4 
  Installing : mysql-community-libs-5.7.29-1.el7.x86_64                                                                                                                                    2/4 
  Installing : mysql-community-client-5.7.29-1.el7.x86_64                                                                                                                                  3/4 
  Installing : mysql-community-server-5.7.29-1.el7.x86_64                                                                                                                                  4/4 
  Verifying  : mysql-community-server-5.7.29-1.el7.x86_64                                                                                                                                  1/4 
  Verifying  : mysql-community-common-5.7.29-1.el7.x86_64                                                                                                                                  2/4 
  Verifying  : mysql-community-libs-5.7.29-1.el7.x86_64                                                                                                                                    3/4 
  Verifying  : mysql-community-client-5.7.29-1.el7.x86_64                                                                                                                                  4/4 

Installed:
  mysql-community-server.x86_64 0:5.7.29-1.el7                                                                                                                                                 

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.29-1.el7                    mysql-community-common.x86_64 0:5.7.29-1.el7                    mysql-community-libs.x86_64 0:5.7.29-1.el7                   

Complete!
[root@iZwz94664y88ud9aroa5veZ ~]# 

修改mysql密码

注意这里grep “password” /var/log/mysqld.log命令是寻找安装过程中的临时密码。

[root@iZwz94664y88ud9aroa5veZ ~]# grep "password" /var/log/mysqld.log
2020-03-31 17:44:01 3766 [Note] Shutting down plugin 'sha256_password'
2020-03-31 17:44:01 3766 [Note] Shutting down plugin 'mysql_old_password'
2020-03-31 17:44:01 3766 [Note] Shutting down plugin 'mysql_native_password'
2020-03-31T10:00:53.353911Z 1 [Note] A temporary password is generated for root@localhost: &zyfqFX#s9e?
2020-03-31T10:01:00.333995Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2020-03-31T10:01:12.451512Z 3 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2020-03-31T10:01:16.504264Z 4 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2020-03-31T10:01:28.012695Z 5 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2020-03-31T10:02:00.319767Z 6 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2020-03-31T10:02:06.880807Z 7 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2020-03-31T10:02:33.736261Z 8 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2020-03-31T10:02:38.628253Z 9 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2020-03-31T10:02:47.675568Z 10 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2020-03-31T10:07:55.960456Z 11 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2020-03-31T10:08:03.545265Z 12 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2020-03-31T10:08:42.988763Z 13 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2020-03-31T10:09:30.865054Z 14 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2020-03-31T10:09:47.856023Z 15 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2020-03-31T10:10:08.229000Z 16 [Note] Access denied for user 'root'@'localhost' (using password: NO)
[[email protected] ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.7.29

Copyright (c) 2000, 2020, 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.

# 修改root的密码
mysql> alter user 'root'@'localhost' identified by 'xxxxxxxx';
Query OK, 0 rows affected (0.01 sec)

# 设置可远程访问
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxxxx' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>  create database test;
Query OK, 1 row affected (0.00 sec)

mysql>  use test
Database changed

#设置数据库编码
mysql>  alter database test character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> SHOW VARIABLES WHERE Variable_name = 'version';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| version       | 5.7.29 |
+---------------+--------+
1 row in set (0.00 sec)

mysql> 


可以看到mysql的版本为5.7.29,升级成功!