当前位置:网站首页>Operating instructions for installing mysql5.7 in centos7

Operating instructions for installing mysql5.7 in centos7

2022-06-12 19:58:00 Astral fleeting year

CentOS7 install MySQL5.7 Operation instructions

0、 Preposition

0.1、 server information

The server IP Address operating system explain
192.168.112.131CentOS7 64 position server information

0.2、MySQL edition

MySQL  Installed version : mysql-5.7.38

1、 Find out if you want to install MySQL

rpm -qa|grep mysql

If an older version of... Is installed MySQL, Please refer to the following methods for unloading

1.1、rpm Install as uninstall

rpm -e --nodeps mysql-XXXXXXXXX

1.2、 Uninstall the binary package installation mode

#  Stop mysql systemctl stop mysqld.service #  Check the status  systemctl status mysqld.service #  lookup mysql find / -name mysql #  Delete the found related files  rm -rf XXXXXX #  View and delete mysql user  id mysql userdel mysql #  Delete profile  rm -f /etc/my.cnf

2、 Find if it exists mariadb package

rpm -qa|grep mariadb

3、 uninstall mariadb package

rpm -e --nodeps mariadb-libs-XXXXXX.el7.x86_64

4、 install MySQL

cd /usr/local mkdir mysql cd mysql wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar tar -xvf mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar

5、 install common,libs,client,server

rpm -ivh mysql-community-common-5.7.38-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-libs-5.7.38-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-client-5.7.38-1.el7.x86_64.rpm --nodeps --force rpm -ivh mysql-community-server-5.7.38-1.el7.x86_64.rpm --nodeps --force ​ #  Check the installation  rpm -qa | grep mysql

6、 Initialization and startup MySQL

#  initialization MySQL mysqld --initialize #  to grant authorization  chown mysql:mysql /var/lib/mysql -R #  start-up MySQL,  In the command  mysqld.service  It can be abbreviated as  mysqld,  The following commands are the same  systemctl start mysqld.service #  Set up MySQL Boot from boot  systemctl enable mysqld.service

explain :MySQL Service related commands are as follows

# 1、 start-up MySQL systemctl start mysqld.service # 2、 stop it MySQL systemctl stop mysqld.service # 3、 restart MySQL systemctl restart mysqld.service # 4、 see MySQL state  systemctl status mysqld.service # 5、 Set up MySQL Self starting  systemctl enable mysqld.sercice # 6、 see MySQL Is it self starting  systemctl list-unit-files|grep mysqld.service

7、 Login and Authorization MySQL

cat /var/log/mysqld.log | grep password mysql -uroot -p

8、 Change Password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

explain : When there is an error that the password cannot be modified , Refer to the following operation

1> error message

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

2> Solution

--  Set password policy verification level  set global validate_password_policy=LOW; --  Set the password verification length  set global validate_password_length=6; --  Refresh cache  flush privileges;

9、 Authorize remote access

--  to root User authorization  create user 'root'@'%' identified with mysql_native_password by '123456'; grant all privileges on *.* to 'root'@'%' with grant option; flush privileges; exit

10、 Firewall configuration

explain : About firewall configuration , Here are two ways to configure , Select according to the system firewall requirements

10.1、 Use CentOS 7 The default firewall firewalld

systemctl start firewalld firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload

explain : About firewalld Firewall related commands are as follows

# 1、 Start firewall service , firewalld.service  It can be abbreviated as  firewalld systemctl start firewalld.service # 2、 Check the running status of firewall service  systemctl status firewalld.service # 3、 Restart firewall service  systemctl restart firewalld.service # 4、 Turn off firewall  systemctl stop firewalld.service # 5、 Boot up the firewall  systemctl enable firewalld.service # 6、 prohibit firewalld Boot up  systemctl disable firewalld.service ## firewall-cmd relevant  # 1、 Add port ,  for example :  add to  3306  port ,  explain : --permanent  The parameter indicates permanent effect , If there is no such parameter, execute  reload  Post failure  firewall-cmd --zone=public --add-port=80/tcp --permanent # 2、 Close the port ,  for example : close 3306 port  firewall-cmd --zone=public --remove-port=3306/tcp --permanent # 3、 Update firewall rules  firewall-cmd --reload # 4、 Look at the open ports ,  for example :  Check out the open  3306  port  firewall-cmd --zone= public --query-port=3306/tcp # 5、 Delete open port ,  for example :  Delete  3306  port  firewall-cmd --zone= public --remove-port=3306/tcp --permanent # 6、 Check all open ports of the firewall  firewall-cmd --zone=public --list-ports # 7、 View firewall status ( Show... When off notrunning, It will show running) firewall-cmd --state # 8、 View firewall version information  firewall-cmd --version

10.2.2、 install iptables A firewall

In the root folder , Execute the following command , install iptables A firewall

yum -y install iptables-services

10.2.3、 Set up and start iptables A firewall

In the root folder , Execute the following command

systemctl enable iptables; systemctl start iptables;

10.2.4、 iptables Configure port access

In the root folder , Execute the following command

vi /etc/sysconfig/iptables

Add the following

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

10.2.5、 restart iptables A firewall

In the root folder , Execute the following command

systemctl restart iptables.service

10.2.6、 Set up iptables The firewall starts up automatically

systemctl enable iptables.service

11、 To configure MySQL

1> Execute the following statement

vi /etc/my.cnf

Add the following configuration information

[client] port = 3306 default-character-set = utf8 [mysqld] character-set-server = utf8 collation-server = utf8_general_ci #  close mysql Case sensitivity ( I.e. requirement mysql Insensitive to the case of a field ) lower_case_table_names = 1

2> After saving the configuration , restart MySQL service

systemctl restart mysqld.service

12、 Use the database connection tool to test

1> View this machine IP Information

ifconfig

2> Use the database connection tool to connect the test

Take the local server information as an example :

 Host name :192.168.112.131  user name :root  password :123456  port :3306
原网站

版权声明
本文为[Astral fleeting year]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121956290318.html