MySQL5.7 nanny level installation tutorial

environment

Linux version Mysql version (to be installed)
CentOS 7 5.7

1. Configure YUM source

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

image-20230810183835867

At present, the MySQL source downloaded from the MySQL official website is installed and the MySQL downloaded by yum is version 8.0. For unnecessary trouble, directly provide the YUM source of MySQL5.7, and execute the following command to install:

# 下载mysql源安装包(无wget命令,先使用yum -y install wget下载wget)
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
#检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"

If you see the picture below, the installation is successful

image-20230810184220682

If you want to install version 5.6 to modify vim /etc/yum.repos.d/mysql-community.repothe source, change the enabled=1 of the 5.7 source to enabled=0. Then change the enabled=0 of the 5.6 source to enabled=1

2. Install MYSQL

#安装命令
yum install mysql-community-server

The following error may occur during installation, which is caused by the expired MySQL GPG key:

image-20230810192725549

Installing the key directly solves the problem:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

In the background of re-executing the installation command, as shown in the figure below, it indicates that the installation is successful

image-20230810193153887

3. Start Mysql

#启动mysql
systemctl start mysqld
#开机启动
systemctl enable mysqld
systemctl daemon-reload
#查看启动状态
systemctl status mysqld

See the following figure to indicate that the startup is successful

image-20230810193433851

4. Change password

After the mysql installation is complete, 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

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

image-20230810193700609

Connect to mysql, change password

 #引号内替换成上述的密码
 mysql -uroot -p'B<AS./rnA3qU'

image-20230810193817549

Change password, enable root remote login

#Change root user password to !@#123QWEasd
ALTER USER 'root'@'localhost' IDENTIFIED BY '!@#123QWEasd';

#Add a user myslave that has all permissions and can connect remotely, password!@#123QWEasd
use mysql;
grant all privileges on . to 'myslave'@'%' identified by '!@#123QWEasd' with grant option;
flush privileges;

# Of course, root can also be modified to allow remote connection
update user set Host='%' where User='root';
flush privileges;

Note : mysql5.7 installs the password security check plug-in (validate_password) by default. The default password check policy requires that the password must contain: uppercase and lowercase letters, numbers and special symbols, and the length should not be less than 8 characters. Otherwise, it will prompt #ERROR 1819 (HY000): Your password does not satisfy the current policy requirements error

5. Common default configuration

At this point, the installation has basically been completed, and the default configuration file path is provided below:

默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

Commonly used configurations are in the /etc/my.cnf file, and we can add encoding configurations under [mysqld], as follows:

#配置默认编码为utf8
character_set_server=utf8
init_connect='SET NAMES utf8'

#bin log
server-id=1  #一般设置成ip,不要重复
expire_logs_days=10
log-bin=/var/lib/mysql/mysql-bin
slave-skip-errors=all

#开启慢日志
slow_query_log=ON
log_output=TABLE
long_query_time=10 #单位s
log_slow_admin_statements=ON
log_slow_slave_statements=ON

Guess you like

Origin blog.csdn.net/yucdsn/article/details/132217536