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

Implementing a simple timer based on Vue method

Vue's simple timer is for your reference. The...

How to connect Navicat to the docker database on the server

Start the mysql container in docekr Use command: ...

Complete steps to upgrade Nginx http to https

The difference between http and https is For some...

How to use display:olck/none to create a menu bar

The effect of completing a menu bar through displ...

Solution to the problem of installing MySQL compressed version zip

There was a problem when installing the compresse...

Detailed tutorial on using the tomcat8-maven-plugin plugin in Maven

I searched a lot of articles online but didn'...

The difference and usage between div and span

Table of contents 1. Differences and characterist...

Summary of three ways to create new elements

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

Solution to the docker command exception "permission denied"

In Linux system, newly install docker and enter t...

WeChat Mini Program Basic Tutorial: Use of Echart

Preface Let’s take a look at the final effect fir...

Combining XML and CSS styles

student.xml <?xml version="1.0" enco...

Summary of commonly used time, date and conversion functions in Mysql

This article mainly summarizes some commonly used...