Detailed tutorial on installing MySQL 8 in CentOS 7

ready

Environmental information in this article:

Software Version
CentOS CentOS 7.4
MySQL 8.0.x

Update all packages of the system before installation

sudo yum update

installation

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

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

After installation, MySQL will start automatically when the system starts. If you don't want it to start automatically, you can use systemctl disable mysqld to close it.

3. change Password

During the MySQL installation process, a temporary password will be generated for the root user and stored in /var/log/mysqld.log. View through the following command:
sudo grep ‘temporary password’ /var/log/mysqld.log

Enter MySQL client to modify:

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

The password strength requirement is: no less than 12 characters, must contain uppercase letters, lowercase letters, numbers and special characters.

3. MySQL security configuration

MySQL includes a security settings wizard script that can be used to modify security options.

sudo mysql_secure_installation

After running, set the following items in sequence:

  1. Modify root account password
  2. Password strength verification plugin (recommended)
  3. Remove anonymous users (recommended)
  4. Disable root account remote login
  5. Remove the test database (test)

Set according to personal situation.

User rights

1. Grant permissions

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

2. Withdraw permission

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

3. Remote login

View user table information in the mysql database:

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

The host of the root user in the table defaults to localhost, which only allows local access. Authorize all permissions of the root user and set up remote access:

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

The default password encryption method for root users is: caching_sha2_password; and many graphical client tools may not support this encryption authentication method, and an error will be reported when connecting. Change the password again with the following command:

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

The password encryption method for root is specified here as mysql_native_password. If you want to change the default password encryption method, you can add a line in 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 [Cloud Server] (https://cloud.tencent.com/product/cvm?from=10680), some service providers (such as Alibaba Cloud) need to go to the console to open the port.

Modify character encoding

The character set is a set of symbols and codes, check 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 effective rule of character set is: Table inherits from Database, and Database inherits from Server. In other words, only character_set_server can be set.

The collation rules are a set of rules for comparing characters in a character set. Check the collation rules:

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|+---------+---------------+--------------------+--------+

Proofreading rules effective rules: If no proofreading rules are set, the character set adopts the default proofreading rules, for example, the proofreading rule for utf8mb4 is utf8mb4_0900_ai_ci.

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

mb4 is most bytes 4. Why is utf8mb4 instead of utf8? The maximum character length of utf8 encoding supported by MySQL is 3 bytes. If a 4-byte wide character is encountered, an exception will be inserted.

The following are the steps to modify the character set of the old version of MySQL to utf8mb4, MySQL 8.0+ does not need to be modified.

# View configuration file location
whereis my.cnf

# open a 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 MySQL commands to check the character set configuration:

show variables like 'charac%';

reference

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 [Ma Nong's little things], more webpage production special effects source code and learning dry goods! ! !

to sum up

The above is a detailed explanation of the tutorial for installing MySQL 8 in CentOS 7 introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message, and the editor will reply to you in time. Thank you very much for your support to the ZaLou.Cn website!

Recommended Posts

Detailed tutorial on installing MySQL 8 in CentOS 7
Detailed tutorial of installing nginx on centos8 (graphic)
Detailed tutorial on installing JDK8 on Linux system (CentOS7 installation)
Detailed tutorial on installing python3.7 for ubuntu18
Detailed tutorial for installing CUDA9.0 on Ubuntu 16.04
Detailed tutorial for installing phpMyAdmin on Ubuntu 18.04
Install MySQL5.7 in centos7
Centos7 install Mysql8 tutorial
Install nginx in centos8 custom directory (detailed tutorial)
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
Install mysql online on centos
Install MySQL 8.0.16 on Linux Centos
vmware install CentOS 7 detailed tutorial
Detailed explanation of CentOS7 network setting tutorial in vmware
Tutorial diagram of installing CentOS 8 (1905) system on VMware virtual machine
Detailed method of installing Kernel 5.x kernel version on CentOS 8 system
How to install MySQL on CentOS 8
Install JDK8 in rpm on CentOS7
Minimal install JDK 1.8 tutorial in CentOS 7
CentOS 8 installation of MariaDB detailed tutorial
CentOS8.1 build Gitlab server detailed tutorial
Detailed use of nmcli in CentOS8
CentOS6 minimal installation KVM detailed tutorial
Install MySql with Docker in CentOS7
Install MySQL on Linux CentOS7 (Windows)
Centos8 installation diagram (super detailed tutorial)
[Switch] CentOS7 64-bit installation mysql tutorial
Tutorial diagram for installing zabbix2.4 under centos6.5
CentOS container installation in Docker uses MySQL
Graphical tutorial for installing JDK1.8 under CentOS7.4
Graphical tutorial for installing Pycharm 2020.1 in Ubuntu 20.04
The most complete centos installation tutorial in history
CentOS7.2 install Mysql5.7.13
CentOS7 install MySQL
CentOS 6.5 system installation and configuration graphic tutorial (detailed graphic)
CentOS8 detailed tutorial for configuring local yum source
Errors and solutions for installing remix-ide on CentOS
Linux (CentOS7) using RPM to install mysql 8.0.11 tutorial
CentOS install mysql
Notes on installing pptp server under CentOS 7 ok
Build LEMP (Linux+Nginx+MySQL+PHP) environment under CentOS 8.1 (detailed tutorial)
CentOS7 install mysql
CentOS 7 install MySQL 5.6
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
CentOS7 install mysql8
MySQL 8.0 installation and deployment under CentOS, super detailed!
Detailed explanation of building Hadoop environment on CentOS 6.5
CentOS7 install MySQL8
Centos MySQL8 configuration
centos 7.5 install mysql5.7.17
The tutorial for upgrading from Centos7 to Centos8 (detailed graphic)
Tutorial for deploying nginx+uwsgi in django project under Centos8
Detailed installation steps of CentOS6.4 system in virtual machine
Detailed steps to install centos on vmware10.0 cracked version
Install Docker on Centos7
install LNMP on centos7.4
Build k8s1.9.9 on centos7
CentOS6.5 offline install MySQL5.6.26
Configure Ocserv on CentOS 6
Install php in centos
Centos install MYSQL8.X tutorial