Home  >  Article  >  Database  >  Detailed tutorial on installing and configuring MySQL 5.7 under CentOS 7

Detailed tutorial on installing and configuring MySQL 5.7 under CentOS 7

小云云
小云云Original
2018-01-11 13:23:311622browse

This article mainly shares with you the detailed tutorial of installing and configuring MySQL 5.7 under CentOS 7. Mysql5.7 is somewhat different from the previous version of MySQL. Now I will write down the complete process of installing and configuring MySQL 5.7 under CentOS 7, which may be useful for novices. Said it was useful.

Test environment for this article:

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


##

# 下载
shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# 安装 mysql 源
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 installation successful

Install MySQL

Use the yum install command to install

shell> ; yum install mysql-community-server

Start MySQL service

Under 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

Modify root local account Password

mysql After the installation is complete, the default password generated 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 with the initial password for the first time, 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!');

Through update set in the future Statement to change password

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

Note: mysql 5.7 The password security check plug-in (validate_password) is 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 prompted. View MySQL official website password detailed policy

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

mysql does not support Chinese by default after installation, and the encoding needs to be modified.

Modify the /etc/my.cnf configuration file and add the encoding configuration under the relevant node (if not, add it yourself), as follows:


Copy the code

The code is 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 that it has been changed

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

View the encoding 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

Related recommendations:

How to install Graylog2 under Centos 7.3 Full guidance

CentOS 7 for ARM one-click Lnmp installation failed

Graphical tutorial on installation and configuration method of mysql 5.7.18 under CentOS 7

The above is the detailed content of Detailed tutorial on installing and configuring MySQL 5.7 under CentOS 7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn