Install and configure MySQL 5.7 under CentOS 7

Install and configure MySQL 5.7 under CentOS 7

This article tests the environment:

CentOS 7 64-bit Minimal MySQL 5.7

Configure yum source

Find the yum source rpm installation package at https://dev.mysql.com/downloads/repo/yum/

rpm installation package

Install mysql source

# Download shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# Install mysql source shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm

Use the following command to check whether the mysql source is installed successfully

shell> yum repolist enabled | grep "mysql.*-community.*" 

mysql source installed successfully

Install MySQL

Install using the yum install command

shell> yum install mysql-community-server

Start MySQL Service

In CentOS 7, the new command to start/stop the service is systemctl start|stop

shell> systemctl start mysqld

Use systemctl status to view MySQL status

shell> systemctl status mysqld

MySQL startup status

Set startup

shell> systemctl enable mysqld shell> systemctl daemon-reload

Change the root local account password

After mysql is installed, the generated default password is in the /var/log/mysqld.log file. Use the grep command to find the password in the log.

shell> grep 'temporary password' /var/log/mysqld.log

View Temporary Password

After logging in for the first time with the initial password, use the following command to change the password

shell> mysql -uroot -p mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

or

mysql> set password for 'root'@'localhost'=password('MyNewPass4!');

Later, change the password through the update set statement

mysql> use mysql; mysql> update user set password=PASSWORD('MyNewPass5!') where user='root';

Note: MySQL 5.7 has a password security check plug-in (validate_password) installed by default. The default password check policy requires that the password must contain uppercase and lowercase letters, numbers, and special symbols, and the length must not be less than 8 characters. Otherwise, the error ERROR 1819 (HY000): Your password does not satisfy the current policy requirements will be displayed. View the detailed password policy on the MySQL official website

Adding a remote login user

By default, only the root account is allowed to log in locally. If you want to connect to MySQL on another machine, you must add an account that allows remote connections. or Modify root to allow remote connections (Not recommended)

Add an account that allows remote connections

mysql> GRANT ALL PRIVILEGES ON *.* TO 'zhangsan'@'%' IDENTIFIED BY 'Zhangsan2018!' WITH GRANT OPTION;

Modify root to allow remote connections (Not recommended)

mysql> use mysql; mysql> UPDATE user SET Host='%' WHERE User='root'; mysql> flush privileges;

Set the default encoding to utf8

After MySQL is installed, it does not support Chinese by default, so the encoding needs to be modified.
Modify the /etc/my.cnf configuration file and add the encoding configuration under the relevant node (if it does not exist, add it yourself), as follows:

Copy the code as follows:

[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

Restart the mysql service and query the encoding. You can see it has been changed.

shell> systemctl restart mysqld shell> mysql -uroot -p mysql> show variables like 'character%';

View the default encoding configuration file path:

Configuration file: /etc/my.cnf
Log file: /var/log/var/log/mysqld.log
Service startup script: /usr/lib/systemd/system/mysqld.service
Socket file: /var/run/mysqld/mysqld.pid

You may also be interested in:
  • How to install and modify the initial password of mysql5.7.18 under Centos7.3
  • MySQL 5.7.17 installation and configuration method graphic tutorial (CentOS7)
  • Linux CentOS MySQL 5.7.18 5.7.X Installation Tutorial
  • Detailed instructions for compiling and installing CentOS MySQL 5.7
  • Detailed tutorial on installing MySQL 5.7.6+ from source in CentOS 7
  • Detailed tutorial for installing mysql5.7.18 on centos7.3
  • CentOS7 uses rpm package to install mysql 5.7.18
  • Detailed steps to compile and install MySQL 5.7.13 on CentOS7 system
  • Centos MySQL 5.7 installation and upgrade tutorial
  • Alibaba Cloud Centos7.3 installation mysql5.7.18 rpm installation tutorial
  • Detailed tutorial for installing mysql 5.7 on centOS 7
  • MySQL 5.7.18 installation and configuration method graphic tutorial (CentOS7)

<<:  How to move a red rectangle with the mouse in Linux character terminal

>>:  What scenarios are not suitable for JS arrow functions?

Recommend

Are you still Select *?

There are many reasons why an application is as s...

Teach you the detailed process of installing DOClever with Docker Compose

Table of contents 1. What is Docker Compose and h...

Experience of redesigning the homepage of TOM.COM

<br />Without any warning, I saw news on cnB...

Pygame code to make a snake game

Table of contents Pygame functions used Creating ...

Example method of deploying react project on nginx

Test project: react-demo Clone your react-demo pr...

Detailed explanation of Vue's ref attribute

Summarize This article ends here. I hope it can b...

sql script function to write postgresql database to implement parsing

This article mainly introduces the sql script fun...

XHTML Getting Started Tutorial: What is XHTML?

What is HTML? To put it simply: HTML is used to m...

Detailed explanation of Linux kernel macro Container_Of

Table of contents 1. How are structures stored in...

Summary of three ways to create new elements

First: via text/HTML var txt1="<h1>Tex...

Detailed explanation of common for loop in JavaScript statements

There are many loop statements in JavaScript, inc...

Detailed explanation of virtual DOM in Vue source code analysis

Why do we need virtual dom? Virtual DOM is design...

CentOS7 upgrade kernel kernel5.0 version

Upgrade process: Original system: CentOS7.3 [root...