0、 Preposition
| The server IP Address | operating system | explain |
|---|---|---|
| 192.168.112.131 | CentOS7 64 position | server information |
0.2、MySQL edition
MySQL Installed version : mysql-5.7.381、 Find out if you want to install MySQL
rpm -qa|grep mysqlIf 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-XXXXXXXXX1.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.cnf2、 Find if it exists mariadb package
rpm -qa|grep mariadb3、 uninstall mariadb package
rpm -e --nodeps mariadb-libs-XXXXXX.el7.x86_644、 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.tar5、 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 mysql6、 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.serviceexplain :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.service7、 Login and Authorization MySQL
cat /var/log/mysqld.log | grep password mysql -uroot -p8、 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 requirements2> 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; exit10、 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 --reloadexplain : 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 --version10.2.2、 install iptables A firewall
In the root folder , Execute the following command , install iptables A firewall
yum -y install iptables-services10.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/iptablesAdd the following
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT10.2.5、 restart iptables A firewall
In the root folder , Execute the following command
systemctl restart iptables.service10.2.6、 Set up iptables The firewall starts up automatically
systemctl enable iptables.service11、 To configure MySQL
1> Execute the following statement
vi /etc/my.cnfAdd 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 = 12> After saving the configuration , restart MySQL service
systemctl restart mysqld.service12、 Use the database connection tool to test
1> View this machine IP Information
ifconfig2> 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








