In the CentOS (Fedora, RedHat) system, you can use yum install mysql
commands to install MySQL, but the MySQL version installed is generally older, so it is recommended to compile the installation by source code or download rpm
the latest installation package for installation.
- Add MySQL
Yum
Source
- Select a Release series
- Using the
Yum
install MySQL
- Start the MySQL server
- ruggedized MySQL Security (MySQL5.6 only)
The source of MySQL Yum
provides the RPM
installation package, including MySQL server, client, and other components of the Linux platform. These installation packages can also be used to upgrade or replace MySQL that is already installed by third parties.
The MySQL Yum
source supports the following Linux platforms:
- Platforms based on el5-, el6-, el7-(e.g. Red Hat Enterprise Linux, Oracle Linux, and CentOS)
- Fedora 23 and 24
1. Add
MySQL
Yum
Source
First, add the MySQL Yum
Source to the list of system sources:
- Open the MySQL
Yum
Source download page: http://dev.mysql.com/downloads/repo/yum/, select and download the applicable release package for your system.
- Install the downloaded release package using the following command
For example, I downloaded the release package for mysql57-community-release-el6-9.noarch.rpm
, the installation command is as follows:
$ sudo rpm-uvh mysql57-community-release-el6-9.noarch.rpm
Note: After the release package is installed, if the system executes a yum update
command (or dnf-enabled
executes a command on the system dnf upgrade
), the MySQL package in the system is automatically upgraded and all local third-party packages are automatically replaced.
2. Select a Release series
MySQL 's Yum
latest GA (General availability, official release) version is installed by default when using MySQL's source. If you are using the latest version, skip this step and view directly using the Yum
install MySQL
Within the MySQL Yum
source, different distribution series correspond to the different resource sub-nodes of the MySQL community server. The child node defaults to the latest official version (currently 5.7), while other resource subnodes (such as 5.5?5.6, etc.) are not available by default.
You can query whether child resources are available ( dnf-enabled
using command overrides in the system) with the following command dnf
yum
:
Yum Repolist All | grep MySQL
mysql-connectors-community MySQL connectors community Enabled:24mysql-connectors-community-source MySQL Co Nnectors community-s disabledmysql-tools-community MySQL Tools Community enabled:40mysql-tools -community-source MySQL tools community-source disabledmysql-tools-preview mysql tools preview Disabledmysql-tools-preview-source MySQL Tools Preview-source disabledmysql55-community My SQL 5.5 Community Server disabledmysql55-community-source MySQL 5.5 Community server-s Disabledmysql56-comm Unity MySQL 5.6 Community server disabledmysql56-community-source mysql 5.6 Community server -S disabledmysql57-community MySQL 5.7 Community Server Enabled:146mysql57-community-source MySQL 5.7 Community server-s disabledmysql80-community MySQL 8.0 Community Server disabledmysql8 0-community-source MySQL 8.0 Community server-s Disabled
As shown above, as the author installs the 5.7 version Yum
source, the 5.7 version is enabled by default.
If you are installing the latest release, no additional configuration is required. To specify that an earlier version be installed, you need to disable the latest occurrence before installation and enable the specified version to be installed. Can be implemented by modifying the /etc/yum.repos.d/mysql-community.repo
file, which is a portal to a specified child resource:
[Mysql-connectors-community]name=mysql Connectors communitybaseurl=http://repo.mysql.com/yum/ mysql-connectors-community/el/6/$basearch/enabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-mysql
As shown above, the latest version 5.7 is enabled by default. If you want to modify the configuration, you can enabled
disable the child resource by editing the configuration node implementation, enable=0
which enabled=1
means that the child resource is enabled.
For example, if you need to enable the 5.6 version of the source, you will need to set the 5.6 version source as shown below to enabled=1
and set the 5.7 version source to enabled=0
:
# Enable to use MySQL 5.6[mysql56-community]name=mysql 5.6 Community serverbaseurl=http://repo.mysql.com/yum/ mysql-5.6-community/el/6/$basearch/enabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-mysql
After the configuration is complete, you can use the command shown earlier to check that the yum repolist enabled | grep mysql
configuration is correct.
3. Use
Yum
Install MySQL
Use the following command to install MySQL ( dnf-enabled
Use command overrides in the system dnf
yum
):
$ sudo yum install Mysql-community-server
The commands above are used to install the MySQL server module, and the command format for installing other modules is similar.
4. Start the MySQL server
Start the MySQL service command as follows:
$ sudo service mysqld start
The following information is output sequentially at startup:
Initializing MySQL Database: [ OK ]installing validate password plugin: [ OK ]starting Mysqld: [ OK ]
You can check the running status of MySQL with the following command:
$ sudo service mysqld status
When the 5.7 version of MySQL starts, because the data directory is empty, the following actions are available:
- Server initialization
- Generate an SSL certificate and key file in the data Catalog
validate_password
Plug-in installation and enablement
- Create a Super Admin account
‘root‘@‘localhost‘
. The managed password is guaranteed to exist in the error log file and can be viewed using the following command:$ sudo grep ' temporary password '/var/log/mysqld.log
You can use the following command to log in with an automatically generated temporary password and then modify it to a custom password:
Password modification:
$ ALTER USER ' root ' @ ' localhost ' identified by ' newpassword ';
Note: The MySQL validate_password
plugin is installed by default. This requires that the MySQL password contain at least one uppercase letter, one lowercase, one number, and one special character, and that the total password length is at least 8 characters.
5. Consolidating MySQL security (MySQL5.6 only)
mysql_secure_installation
The program can ensure the security of some important operations, such as: Modify the root user's password, delete anonymous users, and so on. If the installation is MySQL 5.6, you should always run the program:
$ mysql_secure_installation
Linux CentOS installs MySQL 5.7 with Yum source