Installing a single instance of MySQL 5.7 in a Linux environment

Source: Internet
Author: User
Tags mysql in mysql version ssl connection

First, installation environment

1. Operating system version: CentOS 7.5

2. mysql version: 5.7.22 (Community Edition)

3. mysql installation package: mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

Second, installation steps1. Check if other versions of MySQL are installed in the system (root user)

First check to see if other versions of MySQL are installed on the system and check with the following command:

Yum List Installed | grep MySQL
Yum List Installed | grep mariadb

The MARIADB database is a branch of the MySQL database, and the database is installed by default in the CentOS 7 system and deleted:

Yum Remove mariadb-libs.x86_64

and delete the my.cnf file under the/etc/directory:

Rm–r/etc/my.cnf
2. Install the dependent package (root user)

Installing MySQL in a Linux environment requires the installation of the Libaio dependency package, which causes data catalog initialization and service start failure if the dependency package is not installed.

First check if the Libaio dependency package is already installed on the system:

Yum List Installed | grep Libaio

If the dependent package is not installed, install it:

Yum Install Libaio

For MySQL 5.7.19 and above, you will also need to install the Libnuma dependency package, using the following command to check if the dependency package is installed on the system:

Yum List Installed | grep numactl

If not installed, you can install it using the following command:

Yum Install Numactl
3. Create MySQL user group and MySQL user (root user)

You need to specify the user when initializing MySQL and starting the MySQL service, where you use the MySQL user (and other users and groups).

Create a MySQL user group first:

Groupadd MySQL

Then create the MySQL user and specify the user's owning group as the MySQL user group:

useradd-g MySQL MySQL

Finally, set the login password for the MySQL user:

passwd MySQL
4. Unzip the MySQL installation package (MySQL user)

Copy the MySQL installation package to the installation directory (/app here):

CP mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz/app/

Unzip:

TAR-ZXVF mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

Note:

The success of the above two steps is based on the premise that the MySQL installation package is owned by the MySQL user, and the MySQL user has permission to operate the/app/directory.

You can use the following command to set the owner of a MySQL installation as a MySQL user (root user action):

Chown Mysql:mysql mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

Use the following command to assign operation permissions to the MySQL user (root user action) separately for the/app/directory:

Setfacl-m u:mysql:rwx/app/
5. Renaming (MySQL user)

Rename the extracted directory to MySQL:

MV Mysql-5.7.22-linux-glibc2.12-x86_64/mysql
6. Create data directory (MySQL user)

MySQL version 5.7 does not have its own data directory and needs to be created by itself, into the MySQL directory to create the data directory:

mkdir data
7. Create my.cnf configuration file (MySQL user)

MySQL no longer comes with my.cnf from version 5.7.18 and can create this profile on its own. Create the my.cnf file in the MySQL directory:

Touch my.cnf

Edit My.cnf File:

VI my.cnf

Enter the following in the file:

[mysqld]basedir=/app/mysql/datadir=/app/mysql/data/port=3307user=mysqlcharacter-set-server= Utf8collation-server=utf8_general_ci

Where basedir represents the MySQL root directory, DataDir represents the data storage directory, port is the port number, MySQL default port number is 3306, for security purposes, generally do not use the default port number; user specifies that users who start the MySQL service ; Character-set-server represents the character set used, and Collation-server represents the collation used by the character set.

Note:

The default root directory for MySQL initialization is/usr/local/mysql/, so if you do not specify the root and data directories at initialization time, you need to link/app/mysql/to/usr/local/mysql/. Enter the/usr/local/directory:

cd/usr/local/

Create a soft link map to the/app/mysql/directory:

Ln–s/app/mysql/mysql

Instead of this approach, the MySQL root directory and data directory are specified in the configuration file mode.

8. Initialize MySQL (mysql user)

Go to the Bin directory:

cd/app/mysql/bin/

Initialize MySQL:

./mysqld--defaults-file=/app/mysql/my.cnf–initialize

At this point, MySQL randomly generates a root user's password and needs to remember the password:

9. Generate SSL connection key file (MySQL user)

Use the following command to generate the key file for the encrypted connection:

./mysql_ssl_rsa_setup--DEFAULTS-FILE=/APP/MYSQL/MY.CNF

The results of the implementation are as follows:

10. Start the MySQL service (MySQL user)

Finally, start the MySQL service:

./mysqld_safe--DEFAULTS-FILE=/APP/MYSQL/MY.CNF &
third, modify the root user password

Log in to MySQL with a password that is randomly generated above:

/app/mysql/bin/mysql-u root-p-P 3307

Change the login password of the root user to "root123":

Set password for [email protected] = password (' root123 ');

Installing a single instance of MySQL 5.7 in a Linux environment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.