当前位置:首页 > MySQL
Linux 系统下升级 MySQL 数据库
来源:靑龍一笑的博客  作者:靑龍一笑  发布时间:2019-06-14 12:51:59  点击量:1098  评论:0

    有关 MySQL 的安装,详见我的另一篇文章《Linux 系统下安装 MySQL(重新整理)》。
    升级 MySQL 时需要注意:
    1、发行版本号要与升级前的保持一致,即不应进行跨版本升级,以免升级后出现各种不兼容的问题。
    2、升级前做好数据备份,以免升级过程中的误操作而导致数据丢失。
    这里以 5.6.41 版本的 MySQL 升级到 5.6.43 版本为例,演示 MySQL 的升级过程。
    停止 MySQL:

root@RicenOS:~# service mysql stop

    移走 /etc/my.cnf 文件:

root@RicenOS:~# mv /etc/my.cnf /opt/

    这一步是为了避免在升级过程中,影响到旧的数据。
    解压 MySQL 软件包到 /usr/local 目录下:

root@RicenOS:~# tar xvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

    进入到 /usr/local 目录:

root@RicenOS:~# cd /usr/local/

    如果之前的 MySQL 是按照我的另一篇文章《Linux 系统下安装 MySQL(重新整理)》来操作的话,那么这里就比较简单,只需要修改一下 mysql 软链接的指向即可:

root@RicenOS:/usr/local# ln -snf mysql-5.6.43-linux-glibc2.12-x86_64/ mysql
root@RicenOS:/usr/local# ls -l mysql
lrwxrwxrwx 1 root root 36 6月  14 11:56 mysql -> mysql-5.6.43-linux-glibc2.12-x86_64/

    如果之前是采用其它方式安装 MySQL 的话,这里一定要跟原 MySQL 的安装目录和数据目录区分开。
    进入到 /usr/local/mysql 目录下:

root@RicenOS:/usr/local# cd mysql

    进行初始化安装:

root@RicenOS:/usr/local/mysql# scripts/mysql_install_db --user=mysql

    测试新版本:

root@RicenOS:/usr/local/mysql# bin/mysqld_safe --user=mysql &
root@RicenOS:/usr/local/mysql# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> exit
Bye

    停止 MySQL:

root@RicenOS:/usr/local/mysql# killall mysqld

    还原 /etc/my.cnf 文件:

root@RicenOS:/usr/local/mysql# mv /opt/my.cnf /etc/

    启动 MySQL:

root@RicenOS:/usr/local/mysql# service mysql start

    检测升级结果:

root@RicenOS:/usr/local/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.6.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> show databases;

版权所有 © 2005-2023 靑龍一笑的博客  Powered by C.S.Ricen
Copyright © 2005-2023 by www.ricensoftwares.com.cn  All Rights Reserved.

欢迎光临本站,这里是靑龍一笑的博客。

因资金匮乏,本站已迁到国外的免费空间,可能导致本站的访问速度较慢,由此给您带来的不便,敬请谅解。

您可以通过下方的“支持本站建设”链接,给本站提供资金支持。

Free Web Hosting