MySQL 5.7 installation and configuration tutorial under CentOS7 64 bit

MySQL 5.7 installation and configuration tutorial under CentOS7 64 bit

Installation environment: CentOS7 64-bit MINI version, install MySQL5.7

1. Configure YUM source

Download the YUM source rpm installation package from the MySQL official website: http://dev.mysql.com/downloads/repo/yum/

# Download the mysql source installation package shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# Install mysql source shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm

Check whether the mysql source is installed successfully

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

The above picture shows that the installation is successful.

You can modify the yum source to change the default installed mysql version. For example, if you want to install version 5.7, just change enabled=0 of the 5.7 source to enabled=1. The effect after the modification is as follows:

vim /etc/yum.repos.d/mysql-community.repo 

2. Install MySQL

shell> yum install mysql-community-server

3. Start MySQL service

shell> systemctl start mysqld

Check the startup status of MySQL

4. Start the machine

shell> systemctl enable mysqld
shell> systemctl daemon-reload

5. Modify the root local login password. The root default password may be empty.

1. If the default password is empty, press Enter to log in directly

There is a password. After MySQL is installed, a default password is generated for root in the /var/log/mysqld.log file. Find the root default password in the following way, and then log in to mysql to modify it:

shell> grep 'temporary password' /var/log/mysqld.log
shell>mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 
Or mysql> set password for 'root'@'localhost'=password('MyNewPass4!');

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 message ERROR 1819 (HY000): Your password does not satisfy the current policy requirements will be displayed, as shown in the following figure:

You can view password policy information through the msyql environment variable:

mysql> show variables like '%password%'; 

validate_password_policy: Password policy, the default is MEDIUM policy
validate_password_dictionary_file: Password policy file, required only if the policy is STRONG
validate_password_length: minimum password length
validate_password_mixed_case_count: length of uppercase and lowercase characters, at least 1
validate_password_number_count: at least 1 number
validate_password_special_char_count: at least 1 special character

The above parameters are the password checking rules for the default policy MEDIUM.

There are the following password policies:

MySQL official website password policy detailed description: http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy

Modify Password Policy

Add validate_password_policy configuration in the /etc/my.cnf file to specify the password policy

# Select one of 0 (LOW), 1 (MEDIUM), 2 (STRONG). Selecting 2 requires providing a password dictionary file validate_password_policy=0

If you do not need a password policy, add the following configuration to the my.cnf file to disable it:

validate_password = off

Restart the MySQL service to make the configuration take effect:

systemctl restart mysqld

6. Add remote login user

By default, only the root account is allowed to log in locally. If you want to connect to MySQL on other machines, you must modify root to allow remote connections, or add an account that allows remote connections. For security reasons, I add a new account:

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

7. Configure the default encoding to utf8

Modify the /etc/my.cnf configuration file and add the encoding configuration under [mysqld] as follows:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

Restart the mysql service and check the default database encoding as follows:

Default 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

Uninstall mysql on Centos7

View the current installation status

rpm -qa|grep -i mysql 

yum remove mysql 

rpm -e mysql-community-release-el7-5.noarch

If a dependency error is prompted

Then execute

rpm -ev --nodeps mysql-community-libs-5.6.43-2.el7.x86_64 

Delete in this way

Then find the directory of the old version of mysql and delete the files and libraries of the old version of mysql. I did not delete the old library and directly did an upgrade installation.

find / -name mysql

Delete the corresponding mysql directory

rm -rf /var/lib/mysql 

Note: /etc/my.cnf will not be deleted after uninstallation and needs to be deleted manually

rm -rf /etc/my.cnf

Sometimes my.cnf is not necessarily in /etc, you can use the command to find it

find / -name my.cnf

Check again whether mysql is installed on the machine

rpm -qa|grep -i mysql

I did not delete the original configuration files and database, but directly installed 5.7 and the original database. However, the database could not be used, so I used two commands to solve the problem.

set @@global.show_compatibility_56=ON; 

The original database can be used normally.

Summarize

The above is the installation and configuration tutorial of MySQL5.7 under CentOS7 64-bit introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed steps to install MySQL on CentOS 7
  • A concise tutorial on how to install mysql5.7 decompressed version on CentOS7
  • Centos7 installation and configuration of Mysql5.7
  • MySQL 5.7.17 installation and configuration tutorial under CentOS6.9
  • Detailed tutorial on installing Mysql5.7.19 on Centos7 under Linux
  • How to install mysql5.6 on centos7
  • Centos7 install mysql5.6.29 shell script
  • How to install MySQL on CentOS 7 and set it to start automatically
  • The process of installing MySQL 8.0.26 on CentOS7

<<:  Analysis of centos6 method of deploying kafka project using docker

>>:  Detailed explanation of Vue's monitoring method case

Recommend

Solution for Baidu site search not supporting https (tested)

Recently, https has been enabled on the mobile ph...

Detailed explanation of Vue's methods and properties

Vue methods and properties 1. Methods Usage 1 met...

XHTML Getting Started Tutorial: XHTML Web Page Image Application

<br />Adding pictures reasonably can make a ...

Perfect solution to Google Chrome autofill problem

In Google Chrome, after successful login, Google ...

Windows Server 2008 Tutorial on Monitoring Server Performance

Next, we will learn how to monitor server perform...

How to safely shut down MySQL

When shutting down the MySQL server, various prob...

How to use JS code compiler Monaco

Preface My needs are syntax highlighting, functio...

TCP performance tuning implementation principle and process analysis

Three-way handshake phase Number of retries for c...

Detailed Analysis of Event Bubbling Mechanism in JavaScript

What is bubbling? There are three stages in DOM e...

A detailed tutorial on how to install Jenkins on Docker for beginners

Jenkins is an open source software project. It is...

Detailed explanation of nginx anti-hotlink and anti-crawler configuration

Create a new configuration file (for example, go ...

MySQL index knowledge summary

The establishment of MySQL index is very importan...

JS implements Baidu search box

This article example shares the specific code of ...

Detailed explanation of jquery tag selector application example

This article example shares the specific code of ...