Installing MySQL on Linux Using RPM Packages from Oracle
基于rpm的Linux MySQL安装包的推荐安装方式是使用Oracle提供的rpm包来安装。对于社区版的MySQL,有两种方式来获取安装包:MySQL的软件库(包括MySQL yum源和MySQL sles库)、MySQL开发者空间的下载MySQL社区版服务器界面。
用于安装MySQL的rpm包如下:
Table 2.6 RPM Packages for MySQL Community Edition
| Package Name | Summary |
| mysql-community-server | Database server and related tools 数据库服务器和相关工具 |
| mysql-community-client | MySQL client applications and tools MySQL客户端应用程序和工具 |
| mysql-community-common | Common files for server and client libraries 服务器和客户端库库的通用文件 |
| mysql-community-devel | Development header files and libraries for MySQL database client applications |
| mysql-community-libs | Shared libraries for MySQL database client applications |
| mysql-community-libs-compat | Shared compatibility libraries for previous MySQL installations |
| mysql-community-embedded | MySQL embedded library |
| mysql-community-embedded-devel | Development header files and libraries for MySQL as an embeddable library |
| mysql-community-test | Test suite for the MySQL server |
Table 2.7 RPM Packages for the MySQL Enterprise Edition
| Package Name | Summary |
| mysql-commercial-server | Database server and related tools |
| mysql-commercial-client | MySQL client applications and tools |
| mysql-commercial-common | Common files for server and client libraries |
| mysql-commercial-devel | Development header files and libraries for MySQL database client applications |
| mysql-commercial-libs | Shared libraries for MySQL database client applications |
| mysql-commercial-libs-compat | Shared compatibility libraries for previous MySQL installations |
| mysql-commercial-embedded | MySQL embedded library |
| mysql-commercial-embedded-devel | Development header files and libraries for MySQL as an embeddable library |
| mysql-commercial-test | Test suite for the MySQL server |
rpm包的语法格式:
packagename-version-distribution-arch.rpm
The distribution and arch values indicate the Linux distribution and the processor type for which the package was built. See the table below for lists of the distribution identifiers:
Table 2.8 MySQL Linux RPM Package Distribution Identifiers
| distribution Value | Intended Use |
| el5, el6, el7 | Red Hat Enterprise Linux/Oracle Linux/CentOS 5, 6, or 7 |
| fc22, fc23 | Fedora 22 or 23 |
| sles12 | SUSE Linux Enterprise Server 12 |
查看rpm包中所有文件(for example, mysql-community-server):
shell> rpm -qpl mysql-community-server-version-distribution-arch.rpm
本章剩余章节只适合从Oracle下载的包的安装过程,不适用于MySQL库的安装。
包中存在一些依赖关系。如果你打算安装好几个包,你应该选择下载tar格式的rpm包群,包群里包含了上述所有包,如此一来你便不用分别下载它们。
大多数情况下,你需要安装mysql-community-server, mysql-community-client, mysql-community-libs, mysql-community-common, and mysql-community-libs-compat这五个包来得到一个可用的、标准的MySQL系统。要执行这样一个标准的、最小化的安装,切换到这些包所在的文件夹的路径,在除了Red Hat Enterprise Linux/Oracle Linux/CentOS 5平台下执行如下命令:
shell> sudo yum install mysql-community-{server,client,common,libs}-*
Replace yum with zypper for SLES systems, and with dnf for dnf-enabled systems (like Fedora 22).
对于Red Hat Enterprise Linux/Oracle Linux/CentOS 5平台,有一个额外的包需要安装:mysql-version-el5-arch.rpm,使用如下命令:
shell> sudo yum install mysql-community-{server,client,common,libs}-* mysql-5.*
尽管使用一个高级的包管理工具例如yum来安装包会是极佳的选择,但是仍有用户喜欢直接使用rpm的命令rpm -Uvh来安装,这种方式会增加失败的风险,因为可能会遇到潜在的依赖包的问题。
To install only the client programs, you can skip mysql-community-server in your list of packages to install; issue the following command for platforms other than Red Hat Enterprise Linux/Oracle Linux/CentOS 5:
shell> sudo yum install mysql-community-{client,common,libs}-*
Replace yum with zypper for SLES systems, and with dnf for dnf-enabled systems (like Fedora 22).
For Red Hat Enterprise Linux/Oracle Linux/CentOS 5 systems:
shell> sudo yum install mysql-community-{client,common,libs}-* mysql-5.*
A standard installation of MySQL using the RPM packages result in files and resources created under the system directories, shown in the following table.
MySQL安装的默认布局如下:
Table 2.9 MySQL Installation Layout for Linux RPM Packages from the MySQL Developer Zone
| Files or Resources | Location |
| Client programs and scripts | /usr/bin |
| mysqld server | /usr/sbin |
| Configuration file | /etc/my.cnf |
| Data directory | /var/lib/mysql |
| Error log file |
For RHEL, Oracle Linux, CentOS or Fedora platforms: /var/log/mysqld.log For SLES: /var/log/mysql/mysqld.log |
| Value of secure_file_priv | /var/lib/mysql-files |
| System V init script |
For RHEL, Oracle Linux, CentOS or Fedora platforms: /etc/init.d/mysqld For SLES: /etc/init.d/mysql |
| Systemd service |
For RHEL, Oracle Linux, CentOS or Fedora platforms: mysqld For SLES: mysql |
| Pid file | /var/run/mysql/mysqld.pid |
| Socket | /var/lib/mysql/mysql.sock |
| Keyring directory | /var/lib/mysql-keyring |
| Unix manual pages | /usr/share/man |
| Include (header) files | /usr/include/mysql |
| Libraries | /usr/lib/mysql |
| Miscellaneous support files (for example, error messages, and character set files) | /usr/share/mysql |
安装同时会在操作系统上创建一个名为mysql的用户和一个名为mysql的组。
Note
使用旧的安装包来安装原来的版本的MySQL可能会创建一个叫做/usr/my.cnf的配置文件。强烈建议您检查该文件的内容并将有用的设置迁移到文件/etc/my.cnf中,然后移除/usr/my.cnf。
在安装过程的最后,MySQL并不会自动启动。对于Red Hat Enterprise Linux, Oracle Linux, CentOS, and Fedora systems,使用如下命令启动MySQL:
shell> sudo service mysqld start
对于For SLES systems, 命令一样,但是服务名不同:
shell> sudo service mysql start
如果操作系统启用了systemd,那么标准的service命令例如stop,start,status以及restart都应该可以用来管理MySQL服务器的服务。mysqld服务默认开启,并跟随系统启动。注意,有些事情在systemd平台上会表现的不一致:例如,改变数据目录的位置可能会产生问题。
At the initial start up of the server, the following happens, given that the data directory of the server is empty:
在服务器初始化启动阶段,会发生下列事情,前提是该服务器的数据目录没数据:
- 服务器初始化。
- 一个SSL证书和密钥文件在数据目录中产生。
- validate_password plugin插件安装并生效。
- 一个超级用户帐号'root'@'localhost'创建。该超级用户的密码已设置并存储在错误日志文件中。要找到它,RHEL, Oracle Linux, CentOS, and Fedora systems使用如下命令:
shell> sudo grep 'temporary password' /var/log/mysqld.log
Use the following command for SLES systems:
shell> sudo grep 'temporary password' /var/log/mysql/mysqld.log
接下来是利用刚生成的临时密码登录数据库并为该超级用户帐号设置一个典型的密码:
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
Note
如果安装过程中出现错误,你可以去错误日志文件/var/log/mysqld.log查找相关信息。对于某些Linux平台,有必要提高对mysqld可用的文件描述符的限制。
root passwords for pre-GA releases. For MySQL 5.7.4 and 5.7.5, the initial random root password is written to the .mysql_secret file in the directory named by the HOME environment variable. When trying to access the file, bear in mind that depending on operating system, using a command such as sudo may cause the value of HOME to refer to the home directory of the root system user . .mysql_secret is created with mode 600 to be accessible only to the system user for whom it is created. Before MySQL 5.7.4, the accounts (including root) created in the MySQL grant tables for an RPM installation initially have no passwords; after starting the server, you should assign passwords to them using the instructions in Section 2.10, “Postinstallation Setup and Testing”."