在本章中,我们将介绍以下配方:
在本章中,您将了解 MySQL 8 的安装、升级和降级步骤。有五种不同的安装或升级方式;本章介绍了三种最常用的安装方法:
如果您已经安装了 MySQL 并且想要升级,请按照升级到 MySQL 8一节中的升级步骤进行。如果您的安装已损坏,请在升级到 MySQL 8一节中完成卸载步骤。
安装前,请注意操作系统和 CPU 架构。公约如下:
MySQL Linux RPM 包分发标识符
分布值 | 预期用途 |
---|---|
el6,el7 | Red Hat Enterprise Linux、Oracle Linux、CentOS 6 或 7 |
fc23、fc24、fc25 | 软呢帽 23、24 或 25 |
sles12 | SUSE Linux 企业服务器 12 |
MySQL Linux RPM 包 CPU 标识符
CPU 值 | 预期处理器类型或系列 |
---|---|
i386、i586、i686 | 奔腾处理器或更高版本,32 位 |
x86_64 | 64 位 x86 处理器 |
ia64 | 安腾(IA-64)处理器 |
MySQL Debian 和 Ubuntu 7 和 8 安装包 CPU 标识符
| CPU 值 | 预期处理器类型或系列 | | i386 | 奔腾处理器或更高版本,32 位 | | amd64 | 64 位 x86 处理器 |
MySQL Debian 6 安装包 CPU 标识符
CPU 值 | 预期处理器类型或系列 |
---|---|
i686 | 奔腾处理器或更高版本,32 位 |
x86_64 | 64 位 x86 处理器 |
最常见和最简单的安装方式是通过软件存储库,在其中您可以将正式的 Oracle MySQL 存储库添加到列表中,并通过软件包管理软件安装 MySQL。
存储库软件主要有两种类型:
让我们看一下通过以下方式安装 MySQL 8 的步骤:
shell> cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
shell> sudo yum localinstall -y mysql57-community-release-el7-11.noarch.rpm
Loaded plugins: fastestmirror
Examining mysql57-community-release-el7-11.noarch.rpm: mysql57-community-release-el7-11.noarch
Marking mysql57-community-release-el7-11.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-11 will be installed
--> Finished Dependency Resolution
~
Verifying : mysql57-community-release-el7-11.noarch 1/1
Installed:
mysql57-community-release.noarch 0:el7-11
Complete!
shell> sudo rpm -Uvh "https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm"
Retrieving https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-11 ################################# [100%]
shell> yum repolist enabled | grep 'mysql.*-community.*'
mysql-connectors-community/x86_64 MySQL Connectors Community 42
mysql-tools-community/x86_64 MySQL Tools Community 53
mysql57-community/x86_64 MySQL 5.7 Community Server 227
shell> sudo yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 42
mysql-connectors-community-source MySQL Connectors Community disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 53
mysql-tools-community-source MySQL Tools Community - Sou disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Sourc disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 227
mysql57-community-source MySQL 5.7 Community Server disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server disabled
mysql57-community
和启用mysql80-community
:shell> sudo yum install yum-utils.noarch -y
shell> sudo yum-config-manager --disable mysql57-community
shell> sudo yum-config-manager --enable mysql80-community
mysql80-community
已启用:shell> sudo yum repolist all | grep mysql8
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 16
mysql80-community-source MySQL 8.0 Community Server disabled
shell> sudo yum install -y mysql-community-server
Loaded plugins: fastestmirror
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql80-community | 2.5 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirror.web-ster.com
* epel: mirrors.cat.pdx.edu
* extras: mirrors.oit.uci.edu
* updates: repos.lax.quadranet.com
Resolving Dependencies
~
Transaction test succeeded
Running transaction
Installing : mysql-community-common-8.0.3-0.1.rc.el7.x86_64 1/4
Installing : mysql-community-libs-8.0.3-0.1.rc.el7.x86_64 2/4
Installing : mysql-community-client-8.0.3-0.1.rc.el7.x86_64 3/4
Installing : mysql-community-server-8.0.3-0.1.rc.el7.x86_64 4/4
Verifying : mysql-community-libs-8.0.3-0.1.rc.el7.x86_64 1/4
Verifying : mysql-community-common-8.0.3-0.1.rc.el7.x86_64 2/4
Verifying : mysql-community-client-8.0.3-0.1.rc.el7.x86_64 3/4
Verifying : mysql-community-server-8.0.3-0.1.rc.el7.x86_64 4/4
Installed:
mysql-community-server.x86_64 0:8.0.3-0.1.rc.el7
Dependency Installed:
mysql-community-client.x86_64 0:8.0.3-0.1.rc.el7
mysql-community-common.x86_64 0:8.0.3-0.1.rc.el7
mysql-community-libs.x86_64 0:8.0.3-0.1.rc.el7
Complete!
shell> rpm -qa | grep -i 'mysql.*8.*'
perl-DBD-MySQL-4.023-5.el7.x86_64
mysql-community-libs-8.0.3-0.1.rc.el7.x86_64
mysql-community-common-8.0.3-0.1.rc.el7.x86_64
mysql-community-client-8.0.3-0.1.rc.el7.x86_64
mysql-community-server-8.0.3-0.1.rc.el7.x86_64
.deb
文件来执行。您可以从下载 MySQL APT 存储库 http://dev.mysql.com/downloads/repo/apt/ 。
或者您可以复制链接位置并使用wget
直接下载到服务器上。您可能需要安装wget
(sudo apt-get install wget
:shell> wget "https://repo.mysql.com//mysql-apt-config_0.8.9-1_all.deb"
shell> sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb
(Reading database ... 131133 files and directories currently installed.)
Preparing to unpack mysql-apt-config_0.8.9-1_all.deb ...
Unpacking mysql-apt-config (0.8.9-1) over (0.8.9-1) ...
Setting up mysql-apt-config (0.8.9-1) ...
Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
OK
shell> sudo dpkg-reconfigure mysql-apt-config
shell> sudo apt-get update
shell> sudo apt-get install -y mysql-community-server
~
Processing triggers for ureadahead (0.100.0-19) ...
Setting up mysql-common (8.0.3-rc-1ubuntu14.04) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Setting up mysql-community-client-core (8.0.3-rc-1ubuntu14.04) ...
Setting up mysql-community-server-core (8.0.3-rc-1ubuntu14.04) ...
~
ii
表示包已安装:shell> dpkg -l | grep -i mysql
ii mysql-apt-config 0.8.9-1 all Auto configuration for MySQL APT Repo.
ii mysql-client 8.0.3-rc-1ubuntu14.04 amd64 MySQL Client meta package depending on latest version
ii mysql-common 8.0.3-rc-1ubuntu14.04 amd64 MySQL Common
ii mysql-community-client 8.0.3-rc-1ubuntu14.04 amd64 MySQL Client
ii mysql-community-client-core 8.0.3-rc-1ubuntu14.04 amd64 MySQL Client Core Binaries
ii mysql-community-server 8.0.3-rc-1ubuntu14.04 amd64 MySQL Server
ii mysql-community-server-core 8.0.3-rc-1ubuntu14.04 amd64 MySQL Server Core Binaires
使用存储库安装 MySQL 需要访问公共 internet。作为一种安全措施,大多数生产机器没有连接到互联网。在这种情况下,您可以在 system administration 上下载 RPM 或 DEB 文件,并将其复制到生产机器上。
安装文件主要有两种类型:
您需要安装多个软件包。以下是每一项的列表和简短说明:
mysql-community-server
:数据库服务器及相关工具。mysql-community-client
:MySQL 客户端应用和工具。mysql-community-common
:服务器和客户端库的通用文件。mysql-community-devel
:开发 MySQL 数据库客户端应用程序的头文件和库,如 Perl MySQL 模块。mysql-community-libs
:某些语言和应用程序需要动态加载和使用 MySQL 的共享库(libmysqlclient.so*
)。mysql-community-libs-compat
:旧版本的共享库。如果安装的应用程序与 MySQL 的旧版本动态链接,但希望升级到当前版本而不破坏库依赖关系,请安装此软件包。让我们看一下如何使用以下类型的捆绑包:
shell> wget 'https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.3-0.1.rc.el7.x86_64.rpm-bundle.tar'
~
Saving to: ‘mysql-8.0.3-0.1.rc.el7.x86_64.rpm-bundle.tar’
~
shell> tar xfv mysql-8.0.3-0.1.rc.el7.x86_64.rpm-bundle.tar
shell> sudo rpm -i mysql-community-{server-8,client,common,libs}*
yum
命令(您应该可以访问依赖包):shell> sudo yum install mysql-community-{server-8,client,common,libs}* -y
shell> rpm -qa | grep -i mysql-community
mysql-community-common-8.0.3-0.1.rc.el7.x86_64
mysql-community-libs-compat-8.0.3-0.1.rc.el7.x86_64
mysql-community-libs-8.0.3-0.1.rc.el7.x86_64
mysql-community-server-8.0.3-0.1.rc.el7.x86_64
mysql-community-client-8.0.3-0.1.rc.el7.x86_64
shell> wget "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-server_8.0.3-rc-1ubuntu16.04_amd64.deb-bundle.tar"
~
Saving to: ‘mysql-server_8.0.3-rc-1ubuntu16.04_amd64.deb-bundle.tar’
~
shell> tar -xvf mysql-server_8.0.3-rc-1ubuntu16.04_amd64.deb-bundle.tar
libaio1
软件包,您可能需要安装该软件包:shell> sudo apt-get install -y libaio1
libstdc++6
至最新版本:shell> sudo add-apt-repository ppa:ubuntu-toolchain-r/test
shell> sudo apt-get update
shell> sudo apt-get upgrade -y libstdc++6
libmecab2
至最新版本。如果不包括universe
,则在文件末尾添加以下行(例如zesty
:shell> sudo vi /etc/apt/sources.list
deb http://us.archive.ubuntu.com/ubuntu zesty main universe
shell> sudo apt-get update
shell> sudo apt-get install libmecab2
shell> sudo dpkg-preconfigure mysql-community-server_*.deb
shell> sudo dpkg -i mysql-{common,community-client-core,community-client,client,community-server-core,community-server,server}_*.deb
shell> sudo dpkg -i libmysqlclient21_8.0.1-dmr-1ubuntu16.10_amd64.deb
shell> dpkg -l | grep -i mysql
ii mysql-client 8.0.3-rc-1ubuntu14.04 amd64 MySQL Client meta package depending on latest version
ii mysql-common 8.0.3-rc-1ubuntu14.04 amd64 MySQL Common
ii mysql-community-client 8.0.3-rc-1ubuntu14.04 amd64 MySQL Client
ii mysql-community-client-core 8.0.3-rc-1ubuntu14.04 amd64 MySQL Client Core Binaries
ii mysql-community-server 8.0.3-rc-1ubuntu14.04 amd64 MySQL Server
ii mysql-community-server-core 8.0.3-rc-1ubuntu14.04 amd64 MySQL Server Core Binaires
ii mysql-server 8.0.3-rc-1ubuntu16.04 amd64 MySQL Server meta package depending on latest version
使用软件包安装需要先安装某些依赖项,并且可能与其他软件包冲突。在这种情况下,您可以使用下载页面上提供的通用二进制文件安装 MySQL。二进制文件使用高级编译器进行预编译,并使用最佳性能的最佳选项构建。
MySQL 依赖于libaio
库。如果未在本地安装此库,data directory
初始化和后续服务器启动步骤将失败。
在基于 YUM 的系统上:
shell> sudo yum install -y libaio
基于 APT 的系统:
shell> sudo apt-get install -y libaio1
从 MySQL 下载页面下载 TAR 二进制文件 https://dev.mysql.com/downloads/mysql/ ,然后选择 Linux-Generic 作为操作系统并选择版本。您可以使用wget
命令直接下载到您的服务器上:
shell> cd /opt
shell> wget "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.3-rc-linux-glibc2.12-x86_64.tar.gz"
使用以下步骤安装 MySQL:
mysql
组和mysql
用户。所有文件和目录都应在mysql
用户下:shell> sudo groupadd mysql
shell> sudo useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> sudo tar zxvf /opt/mysql-8.0.3-rc-linux-glibc2.12-x86_64.tar.gz
mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/myisamlog
mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/myisampack
mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/mysql
~
shell> sudo ln -s mysql-8.0.3-rc-linux-glibc2.12-x86_64 mysql
mysql
:shell> cd mysql
shell> sudo mkdir mysql-files
shell> sudo chmod 750 mysql-files
shell> sudo chown -R mysql .
shell> sudo chgrp -R mysql .
mysql
,生成临时密码:shell> sudo bin/mysqld --initialize --user=mysql
~
2017-12-02T05:55:10.822139Z 5 [Note] A temporary password is generated for root@localhost: Aw=ee.rf(6Ua
~
root@localhost: eJQdj8C*qVMq
生成了一个临时密码:shell> sudo bin/mysql_ssl_rsa_setup
Generating a 2048 bit RSA private key
...........+++
....................................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
...........................................................+++
...........................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
.....+++
..........................+++
writing new private key to 'client-key.pem'
-----
root
,将data
文件的所有权更改为mysql
:shell> sudo chown -R root .
shell> sudo chown -R mysql data mysql-files
init.d
:shell> sudo cp support-files/mysql.server /etc/init.d/mysql
mysql
的二进制文件导出到PATH
环境变量:shell> export PATH=$PATH:/usr/local/mysql/bin
安装完成后,您将在/usr/local/mysql
中获得以下目录:
| 目录 | 目录的内容 |
| bin
| mysqld
服务器、客户端和实用程序 |
| data
| 日志文件、数据库 |
| docs
| 信息格式的 MySQL 手册 |
| man
| Unix 手册页 |
| include
| 包括(头)文件 |
| lib
| 图书馆 |
| share
| 其他支持文件,包括错误消息、示例配置文件、用于数据库安装的 SQL |
还有其他安装方法,例如:
安装完成后,可以使用以下命令启动/停止 MySQL,这些命令因平台和安装方法而异。mysqld
是mysql
服务器进程。所有的启动方法都会调用mysqld
脚本。
让我们详细看看。除了启动和停止,我们还将了解有关检查服务器状态的内容。让我们看看如何。
您可以使用以下命令启动服务器:
service
:shell> sudo service mysql start
init.d
:shell> sudo /etc/init.d/mysql start
shell> sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
systemd
支持:shell> sudo systemctl start mysqld
systemd
支持,可以使用mysqld_safe
启动 MySQL。mysqld_safe
是mysqld
的启动程序脚本,用于保护mysqld
流程。如果mysqld
被终止,mysqld_safe
尝试再次启动流程:shell> sudo mysqld_safe --user=mysql &
启动后,
data directory
中生成。validate_password
插件已安装并启用。root'@'localhost
。超级用户的密码设置并存储在错误日志文件中(不适用于二进制安装)。要显示它,请使用以下命令:shell> sudo grep "temporary password" /var/log/mysqld.log
2017-12-02T07:23:20.915827Z 5 [Note] A temporary password is generated for root@localhost: bkvotsG:h6jD
您可以使用该临时密码连接到 MySQL。
shell> mysql -u root -pbkvotsG:h6jD
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.3-rc-log
Copyright (c) 2000, 2017, 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>
# You will be prompted for a password, enter the one you got from the previous step
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass4!';
Query OK, 0 rows affected (0.01 sec)
# password should contain at least one Upper case letter, one lowercase letter, one digit, and one special character, and that the total password length is at least 8 characters
停止 MySQL 并检查状态与启动 MySQL 类似,只是更改了一个字:
service
:shell> sudo service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
init.d
:shell> sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
systemd
支持(请参阅使用 systemd管理 MySQL 服务器部分):
shell> sudo systemctl stop mysqld
mysqladmin
:shell> mysqladmin -u root -p shutdown
service
:shell> sudo systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mysqld.service.d
└─override.conf
Active: active (running) since Sat 2017-12-02 07:33:53 UTC; 14s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 10472 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 10451 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 10477 (mysqld)
CGroup: /system.slice/mysqld.service
└─10477 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid --general_log=1
Dec 02 07:33:51 centos7 systemd[1]: Starting MySQL Server...
Dec 02 07:33:53 centos7 systemd[1]: Started MySQL Server.
init.d
:shell> sudo /etc/init.d/mysql status
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/init.d/mysql; bad; vendor preset: enabled)
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)
Dec 02 06:01:00 ubuntu systemd[1]: Starting LSB: start and stop MySQL...
Dec 02 06:01:00 ubuntu mysql[20334]: Starting MySQL
Dec 02 06:01:00 ubuntu mysql[20334]: *
Dec 02 06:01:00 ubuntu systemd[1]: Started LSB: start and stop MySQL.
Dec 02 06:01:00 ubuntu mysql[20334]: 2017-12-02T06:01:00.969284Z mysqld_safe A mysqld process already exists
Dec 02 06:01:55 ubuntu systemd[1]: Stopping LSB: start and stop MySQL...
Dec 02 06:01:55 ubuntu mysql[20445]: Shutting down MySQL
Dec 02 06:01:57 ubuntu mysql[20445]: .. *
Dec 02 06:01:57 ubuntu systemd[1]: Stopped LSB: start and stop MySQL.
Dec 02 07:26:33 ubuntu systemd[1]: Stopped LSB: start and stop MySQL.
systemd
支持(请参阅使用 systemd 管理 MySQL 服务器部分):shell> sudo systemctl status mysqld
如果您的安装有问题,或者您不想要 MySQL 8 版本,您可以使用以下步骤卸载。卸载前,如果需要,请确保备份文件(参见第 7 章、备份),并停止 MySQL。
卸载将在不同的系统上以不同的方式处理。让我们来看看如何。
shell> rpm -qa | grep -i mysql-community
mysql-community-libs-8.0.3-0.1.rc.el7.x86_64
mysql-community-common-8.0.3-0.1.rc.el7.x86_64
mysql-community-client-8.0.3-0.1.rc.el7.x86_64
mysql-community-libs-compat-8.0.3-0.1.rc.el7.x86_64
mysql-community-server-8.0.3-0.1.rc.el7.x86_64
--nodeps
选项忽略警告:shell> rpm -e <package-name>
例如:
shell> sudo rpm -e mysql-community-server
shell> sudo rpm -qa | grep -i mysql-community | xargs sudo rpm -e --nodeps
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
shell> dpkg -l | grep -i mysql
shell> sudo apt-get remove mysql-community-server mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-server mysql-community-server-core -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-server mysql-community-server-core mysql-server
0 upgraded, 0 newly installed, 7 to remove and 341 not upgraded.
After this operation, 357 MB disk space will be freed.
(Reading database ... 134358 files and directories currently installed.)
Removing mysql-server (8.0.3-rc-1ubuntu16.04) ...
Removing mysql-community-server (8.0.3-rc-1ubuntu16.04) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Removing mysql-client (8.0.3-rc-1ubuntu16.04) ...
Removing mysql-community-client (8.0.3-rc-1ubuntu16.04) ...
Removing mysql-common (8.0.3-rc-1ubuntu16.04) ...
Removing mysql-community-client-core (8.0.3-rc-1ubuntu16.04) ...
Removing mysql-community-server-core (8.0.3-rc-1ubuntu16.04) ...
Processing triggers for man-db (2.7.5-1) ...
或使用以下方法删除它们:
shell> sudo apt-get remove --purge mysql-\* -y
shell> sudo apt-get autoremove -y
shell> dpkg -l | grep -i mysql
ii mysql-apt-config 0.8.9-1 all Auto configuration for MySQL APT Repo.
rc mysql-common 8.0.3-rc-1ubuntu16.04 amd64 MySQL Common
rc mysql-community-client 8.0.3-rc-1ubuntu16.04 amd64 MySQL Client
rc mysql-community-server 8.0.3-rc-1ubuntu16.04 amd64 MySQL Server
rc
表示包已被删除(r
),仅保留配置文件(c
)。
卸载二进制安装非常简单。您只需删除符号链接即可:
shell> cd /usr/local
mysql
指向何处,将显示其引用的路径:shell> sudo ls -lh mysql
mysql
:shell> sudo rm mysql
shell> sudo rm -f /opt/mysql-8.0.3-rc-linux-glibc2.12-x86_64.tar.gz
如果您使用 RPM 或 Debian 软件包服务器安装 MySQL,则启动和关闭由systemd
管理。在安装了对 MySQL 的systemd
支持的平台上,mysqld_safe
、mysqld_multi
和mysqld_multi.server
未安装。MySQL 服务器的启动和关闭由systemd
使用systemctl
命令进行管理。您需要如下配置systemd
。
RPM-based systems use the mysqld.service
files, and APT-based systems use the mysql.server
files.
systemd
配置文件:shell> sudo mkdir -pv /etc/systemd/system/mysqld.service.d
conf
文件:shell> sudo vi /etc/systemd/system/mysqld.service.d/override.conf
[Service]
LimitNOFILE=max_open_files (ex: 102400)
PIDFile=/path/to/pid/file (ex: /var/lib/mysql/mysql.pid)
Nice=nice_level (ex: -10)
Environment="LD_PRELOAD=/path/to/malloc/library" Environment="TZ=time_zone_setting"
systemd
:shell> sudo systemctl daemon-reload
conf
文件的情况下重新加载:shell> sudo systemctl set-environment MYSQLD_OPTS="--general_log=1"
or unset using
shell> sudo systemctl unset-environment MYSQLD_OPTS
systemd
环境后,重启服务器,使更改生效。
启用mysql.serviceshell> sudo systemctl
和启用mysql.service
:shell> sudo systemctl unmask mysql.service
mysql
:
:shell> sudo systemctl restart mysqld
在 Debian 平台上:
shell> sudo systemctl restart mysql
如果您的应用程序没有按预期运行,您可以随时降级到以前的 GA 版本(MySQL 5.7)。降级前,建议进行逻辑备份(参见第 7 章、备份)。请注意,您只能通过一个早期版本进行降级。假设你想从 MySQL 8.0 降级到 MySQL 5.6,你必须先降级到 MySQL 5.7,然后再从 MySQL 5.7 降级到 MySQL 5.6。
您可以通过两种方式完成:
在以下小节中,您将学习如何使用各种存储库、捆绑包等处理安装/卸载/升级/降级。
对于 MySQL 8.0 中 GA 状态版本之间的降级(请注意,您不能使用此方法降级到 MySQL 5.7):
data directory
上重启 MySQLmysql_upgrade
实用程序mysql> SET GLOBAL innodb_fast_shutdown = 0;
mysql
服务器,如停止 MySQL 8.0 服务器部分所述:shell> sudo systemctl stop mysqld
data directory
中删除InnoDB
重做日志文件(ib_logfile*
文件),以避免在发布之间发生与重做日志文件格式更改相关的降级问题:shell> sudo rm -rf /var/lib/mysql/ib_logfile*
降级 MySQL。要降级服务器,您需要卸载 MySQL 8.0,如卸载 MySQL 8一节所述。配置文件将自动存储为备份。
列出可用版本:
shell> sudo yum list mysql-community-server
降级是棘手的;最好在降级之前删除现有包:
shell> sudo rpm -qa | grep -i mysql-community | xargs sudo rpm -e --nodeps
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
安装旧版本:
shell> sudo yum install -y mysql-community-server-<version>
shell> sudo dpkg-reconfigure mysql-apt-config
apt-get update
:shell> sudo apt-get update
shell> sudo apt-get remove mysql-community-server mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-server mysql-community-server-core -y
shell> sudo apt-get autoremove
shell> sudo apt-get install -y mysql-server
卸载现有软件包(参见卸载 MySQL 8部分)并安装新的软件包,可以从 MySQL 下载下载(参见使用 RPM 或 DEB 文件安装 MySQL 8.0部分)。
如果您已通过二进制文件安装 MySQL,则必须删除旧版本的符号链接(请参阅卸载 MySQL 8部分)并重新安装(请参阅使用通用二进制文件在 Linux 上安装 MySQL部分):
mysql_upgrade
实用程序:shell> sudo mysql_upgrade -u root -p
shell> sudo systemctl restart mysqld
以下是步骤的概要:
mysql_upgrade
实用程序以下是详细的步骤:
mydumper
的更快备份):shell> mysqldump -u root -p --add-drop-table --routines --events --all-databases --force > mysql80.sql
data directory
。如果您想保留 MySQL 8,我们可以将data directory
移回,而不是恢复 SQL 备份(在步骤 1 中):shell> sudo mv /var/lib/mysql /var/lib/mysql80
卸载后,安装旧版本:
shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community
mysql57-community
已启用:shell> yum repolist enabled | grep "mysql.*-community.*"
!mysql-connectors-community/x86_64 MySQL Connectors Community 42
!mysql-tools-community/x86_64 MySQL Tools Community 53
!mysql57-community/x86_64 MySQL 5.7 Community Server 227
shell> sudo rpm -qa | grep -i mysql-community | xargs sudo rpm -e --nodeps
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave
shell> sudo yum list mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.rackspace.com
* epel: mirrors.develooper.com
* extras: centos.s.uw.edu
* updates: mirrors.syringanetworks.net
Available Packages
mysql-community-server.x86_64 5.7.20-1.el7 mysql57-community
shell> sudo yum install -y mysql-community-server
apt
切换到 MySQL 5.7:shell> sudo dpkg-reconfigure mysql-apt-config
apt-get update
:shell> sudo apt-get update
shell> sudo apt-get remove mysql-community-server mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-server mysql-community-server-core -y
shell> sudo apt-get autoremove
shell> sudo apt-get install -y mysql-server
卸载现有的软件包(参见卸载 MySQL 8部分)并安装新的软件包,可以从 MySQL 下载下载(参见使用 RPM 或 DEB 文件安装 MySQL 8部分)。
如果您已通过二进制文件安装 MySQL,则必须删除旧版本的符号链接(请参阅卸载 MySQL 8一节)并重新安装(请参阅使用通用二进制文件在 Linux 上安装 MySQL一节)。
降级 MySQL 后,必须恢复备份并运行mysql_upgrade
实用程序:
myloader
的快速恢复方法:shell> mysql -u root -p < mysql80.sql
mysql_upgrade
:shell> mysql_upgrade -u root -p
shell> sudo /etc/init.d/mysql restart
MySQL 8 使用包含事务表中数据库对象信息的全局data dictionary
。在以前的版本中,字典数据存储在元数据文件和非事务性系统表中。您需要将您的data directory
从基于文件的结构升级到数据字典结构。
就像降级一样,您可以使用两种方法进行升级:
您还应该在升级之前检查一些先决条件。
shell> sudo mysqlcheck -u root -p --all-databases --check-upgrade
shell> SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE ENGINE NOT IN ('innodb', 'ndbcluster') AND CREATE_OPTIONS LIKE '%partitioned%';
如果存在这些表格中的任何一个,请将其更改为InnoDB
:
mysql> ALTER TABLE table_name ENGINE = INNODB;
或删除分区:
mysql> ALTER TABLE table_name REMOVE PARTITIONING;
mysql
系统数据库中不能有与 MySQL 8.0data dictionary
使用的表同名的表。要使用这些名称标识表,请执行以下查询:mysql> SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE LOWER(TABLE_SCHEMA) = 'mysql' and LOWER(TABLE_NAME) IN ('catalogs', 'character_sets', 'collations', 'column_type_elements', 'columns', 'events', 'foreign_key_column_usage', 'foreign_keys', 'index_column_usage', 'index_partitions', 'index_stats', 'indexes', 'parameter_type_elements', 'parameters', 'routines', 'schemata', 'st_spatial_reference_systems', 'table_partition_values', 'table_partitions', 'table_stats', 'tables', 'tablespace_files', 'tablespaces', 'triggers', 'version', 'view_routine_usage', 'view_table_usage');
mysql> SELECT CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE LENGTH(CONSTRAINT_NAME) > 64;
ndb
应该移动到InnoDB
:mysql> ALTER TABLE tablename ENGINE=InnoDB;
与前面的配方一样,以下小节将带您了解各种系统、捆绑包等的详细信息。
以下是步骤的概要:
data directory
上重新启动 MySQL。mysql_upgrade
实用程序。InnoDB
表空间,则通过执行以下语句旋转keyring
主密钥:mysql> ALTER INSTANCE ROTATE INNODB MASTER KEY;
以下是详细的步骤:
InnoDB
在关闭前执行完全清除和更改缓冲区合并,以确保撤销日志为空,并在版本之间出现文件格式差异时充分准备数据文件。
这一步是最重要的,因为如果没有这一步,您将导致以下错误:[ERROR] InnoDB: Upgrade after a crash is not supported.
此重做日志是使用 MySQL 5.7.18 创建的。请按照中的说明操作 http://dev.mysql.com/doc/refman/8.0/en/upgrading.html :
mysql> SET GLOBAL innodb_fast_shutdown = 0;
升级 MySQL 二进制文件或包。
shell> sudo yum-config-manager --disable mysql57-community
shell> sudo yum-config-manager --enable mysql80-community
mysql80-community
已启用:shell> sudo yum repolist all | grep mysql8
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 16
mysql80-community-source MySQL 8.0 Community Server disabled
shell> sudo yum update mysql-server
apt
切换到 MySQl 8.0:shell> sudo dpkg-reconfigure mysql-apt-config
apt-get update
:shell> sudo apt-get update
shell> sudo apt-get remove mysql-community-server mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-server mysql-community-server-core -y
shell> sudo apt-get autoremove
shell> sudo apt-get update
shell> sudo apt-get install mysql-server
shell> sudo apt-get install libmysqlclient21
卸载现有软件包(请参阅卸载 MySQL 8部分)并安装新的软件包,可以从 MySQL 下载下载(请参阅使用 RPM 或 DEB 文件安装 MySQL 8.0部分)。
如果您已通过二进制文件安装 MySQL,则必须删除旧版本的符号链接(请参阅卸载 MySQL 8一节)并重新安装(请参阅使用通用二进制文件在 Linux 上安装 MySQL一节)。
启动 MySQL 8.0 服务器(参见启动或停止 MySQL 8 启动 MySQL部分)。如果存在加密的InnoDB
表空间,请使用--early-plugin-load
选项加载keyring
插件。
服务器自动检测data dictionary
表是否存在。如果没有,服务器将在data directory
中创建它们,用元数据填充它们,然后继续正常的启动顺序。在此过程中,服务器升级所有数据库对象的元数据,包括数据库、表空间、系统和用户表、视图以及存储程序(存储过程和函数、触发器、事件调度器事件)。服务器还删除以前用于元数据存储的文件。例如,升级后,您会注意到表中不再有.frm
文件。
服务器创建一个名为backup_metadata_57
的目录,并将 MySQL 5.7 使用的文件移动到其中。服务器将event
和proc
表重命名为event_backup_57
和proc_backup_57
。如果升级失败,服务器将恢复对data directory
的所有更改。在这种情况下,您应该删除所有重做日志文件,在同一个data directory
上启动 MySQL 5.7 服务器,并修复任何错误的原因。然后,再次缓慢关闭 5.7 服务器并启动 MySQL 8.0 服务器重试。
运行mysql_upgrade
实用程序:
shell> sudo mysql_upgrade -u root -p
mysql_upgrade
检查所有数据库中的所有表是否与当前版本的 MySQL 不兼容。它在 MySQL 5.7 和 MySQL 8.0 之间的mysql
系统数据库中进行所需的任何剩余更改,以便您可以利用新的特权或功能。mysql_upgrade
还更新了 MySQL 8.0 的性能模式INFORMATION_SCHEMA
和sys schema
对象。
重启 MySQL 服务器(参见启动或停止 MySQL 8 启动 MySQL一节)。
以下是步骤的概要:
mysqldump
从旧 MySQL 版本导出现有数据mysql_upgrade
实用程序以下是详细的步骤:
mydumper
的更快备份):shell> mysqldump -u root -p --add-drop-table --routines --events --all-databases --ignore-table=mysql.innodb_table_stats --ignore-table=mysql.innodb_index_stats --force > data-for-upgrade.sql
root
密码:shell> mysql -u root -p
Enter password: **** (enter temporary root password from error log)
mysql> ALTER USER USER() IDENTIFIED BY 'your new password';
myloader
的快速恢复方法,请参见第 8 章、恢复数据:shell> mysql -u root -p --force < data-for-upgrade.sql
mysql_upgrade
实用程序:shell> sudo mysql_upgrade -u root -p
MySQL 实用程序为您提供了非常方便的工具,无需大量手动操作即可顺利执行日常操作。
它可以按以下方式安装在基于 YUM 和基于 APT 的系统上。让我们看一看。
从 MySQL 下载页面下载文件 https://dev.mysql.com/downloads/utilities/ ,通过选择 Red Hat Enterprise Linux/Oracle Linux,或直接从此链接使用wget
:
shell> wget https://cdn.mysql.com//Downloads/MySQLGUITools/mysql-utilities-1.6.5-1.el7.noarch.rpm
shell> sudo yum localinstall -y mysql-utilities-1.6.5-1.el7.noarch.rpm
从 MySQL 下载页面下载文件 https://dev.mysql.com/downloads/utilities/ ,通过选择 Ubuntu Linux,或直接从此链接使用wget
:
shell> wget "https://cdn.mysql.com//Downloads/MySQLGUITools/mysql-utilities_1.6.5-1ubuntu16.10_all.deb"
shell> sudo dpkg -i mysql-utilities_1.6.5-1ubuntu16.10_all.deb
shell> sudo apt-get install -f