Detailed tutorial on installing MySQL 8 in CentOS 7

Detailed tutorial on installing MySQL 8 in CentOS 7

Prepare

Environmental information for this article:

software Version
CentOS CentOS 7.4
MySQL 8.0.x

Update all system packages before installation

sudo yum update

Install

1. Add Yum package

wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
# or wget http://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
sudo yum update
sudo rpm -ivh mysql80-community-release-el7-1.noarch.rpm

Note: You can find the latest rpm package name on the official website.

2. Install MySQL

# Install sudo yum -y install mysql-community-server
# Start the daemon process sudo systemctl start mysqld
# Check the status sudo systemctl status mysqld
# Check the version mysql -V

After installation, MySQL will start automatically when the system starts. If you do not want it to start automatically, you can use systemctl disable mysqld to shut it down.

3. Change password

During the MySQL installation process, a temporary password is generated for the root user and saved in /var/log/mysqld.log. View it by using the following command:
sudo grep 'temporary password' /var/log/mysqld.log

Enter the MySQL client and modify:

mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password';
# ALTER USER 'root'@ IDENTIFIED BY 'your password';

Password strength requirements are: no less than 12 characters, must contain uppercase letters, lowercase letters, numbers and special characters.

3. MySQL security configuration

MySQL includes a Security Wizard script that you can use to modify security options.

sudo mysql_secure_installation

After running, set the following items in sequence:

1. Change the root account password
2. Password strength verification plug-in (recommended)
3. Remove anonymous users (recommended)
4. Disable remote login of root account
5. Remove the test database (test)

Set according to personal circumstances.

User Permissions

1. Grant permissions

# Create a local user CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
# Create a new remote user CREATE USER 'user'@'%' IDENTIFIED BY 'password';
# Create a new database CREATE DATABASE test_db;
# View user permissions SHOW GRANTS FOR 'user'@'%';
# Grant the user remote access rights to the specified database GRANT ALL PRIVILEGES ON test_db.* TO 'user'@'%';
# Grant the user remote access rights to all databases GRANT ALL PRIVILEGES ON *.* TO 'user'@'%';
# Grant the user local access rights to all databases GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost';
# FLUSH PRIVILEGES;

2. Revoke permissions

# Revoke permissions REVOKE ALL PRIVILEGES ON *.* FROM 'test'@'%';
# Delete local user DROP USER 'user'@'localhost';
# Delete remote user DROP USER 'user'@'%';
# FLUSH PRIVILEGES;

3. Remote login

View the user table information in the mysql database:

use mysql;
select host, user, authentication_string, plugin from user;

The default host for the root user in the table is localhost, which only allows local access. Grant full permissions to the root user and set up remote access:

# Authorization GRANT ALL ON *.* TO 'root'@'%';
# FLUSH PRIVILEGES;

The default password encryption method for the root user is: caching_sha2_password; however, many graphical client tools may not support this encryption authentication method and will report an error when connecting. Re-change the password using the following command:

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your password';

Here the root password encryption method is specified as mysql_native_password. If you want to change the default password encryption method, you can add a line to the /etc/my.cnf file:

default-authentication-plugin=mysql_native_password

If the server has a firewall enabled, port 3306 needs to be opened.

firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload

Note: If it is a cloud server, some service providers (such as Alibaba Cloud) require you to open ports in the console.

Change character encoding

A character set is a set of symbols and encodings. To view the character set configuration:

mysql> show variables like 'charac%';
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+

The character set takes effect as follows: Table inherits from Database, and Database inherits from Server. That is, only character_set_server can be set.

A collation is a set of rules used to compare characters within a character set. To view collation:

mysql> show character set like 'utf8%';
+---------+---------------+--------------------+--------+
| Charset | Description | Default collation | Maxlen |
+---------+---------------+--------------------+--------+
| utf8 | UTF-8 Unicode | utf8_general_ci | 3 |
| utf8mb4 | UTF-8 Unicode | utf8mb4_0900_ai_ci | 4 |
+---------+---------------+--------------------+--------+

Collation rule effectiveness rules: If no collation rule is set, the character set uses the default collation rule, for example, the collation rule of utf8mb4 is utf8mb4_0900_ai_ci.

The default character set of MySQL 8 has been changed to utf8mb4. If the default character set of previous MySQL versions is not utf8mb4, it is recommended to change it to utf8mb4.

mb4 means most bytes 4. Why utf8mb4, not utf8? The maximum character length of the utf8 encoding supported by MySQL is 3 bytes. If a 4-byte wide character is encountered, an insertion exception will occur.

The following are the steps to change the character set to utf8mb4 for older versions of MySQL. No modification is required for MySQL 8.0+.

# View the configuration file location whereis my.cnf

# Open the file vi /etc/my.cnf

Add character encoding configuration items:

[client]
default-character-set=utf8mb4

[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci

Restart MySQL service

sudo systemctl restart mysqld

Use the MySQL command to check the character set configuration:

show variables like 'charac%';

refer to

https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

https://ken.io/note/centos-mysql8-setup

recommend:

Interested friends can follow the editor’s WeChat public account [ Coder’s Stuff ] for more web page production special effects source code and learning materials! ! !

Summarize

The above is a detailed tutorial on how to install MySQL 8 in CentOS 7. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Detailed tutorial on installing MySQL 8.0 from source code on CentOS 7.4
  • Installation tutorial of mysql8.0rpm on centos7
  • Detailed steps to install Mysql5.7.19 using yum on Centos7
  • Detailed tutorial on installing Mysql5.7.19 on Centos7 under Linux
  • How to install MySQL using yum on Centos7 and achieve remote connection
  • How to quickly install MySQL 5.7 using YUM under Centos 7.2

<<:  How to use localStorage in JavaScript

>>:  MySQL 5.7.17 winx64 installation and configuration tutorial

Recommend

Use of Linux network configuration tools

This article introduces RHEL8 network services an...

Conditional comment style writing method and sample code

As front-end engineers, IE must be familiar to us...

Summary of CSS counter and content

The content property was introduced as early as C...

How to reasonably use the redundant fields of the database

privot is the intermediate table of many-to-many ...

How to publish a locally built docker image to dockerhub

Today we will introduce how to publish the local ...

Detailed explanation of Windows time server configuration method

Recently, I found that the company's server t...

In-depth explanation of the style feature in Vue3 single-file components

Table of contents style scoped style module State...

Do you know what are the ways to jump routes in Vue?

Table of contents The first method: router-link (...

Vue achieves seamless carousel effect

This article shares the specific code of Vue to a...

Handwritten Vue2.0 data hijacking example

Table of contents 1: Build webpack 2. Data hijack...

A brief discussion on CSS cascading mechanism

Why does CSS have a cascading mechanism? Because ...

Solve the error of installing VMware Tools on Ubuntu 18.04

1. According to the online tutorial, the installa...

Web designer's growth experience

<br />First of all, I have to state that I a...