Centos7 Using yum to Install MySQL and Realize Remote Connection Method
- 2021-08-31 09:29:43
- OfStack
Centos7 uses yum to install MySQL and how to connect remotely, since MySQL was acquired by Oracle, the mariadb database is currently recommended
The steps are as follows:
1)yum install mariadb
2) yum install mariadb-server
3) yum install mariadb-devel
chmod -R 770 /var/lib/mysql
systemctl restart mariadb.service
At this point, MySQL installation is complete
Initialization password:
Execute the mysql command to set the initial password
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('input the password you like');
tips:
Connect to the database remotely:
1)mysql -u root -p password ;use mysql ;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; Allow any ip With root User login
flush privileges; Effective immediately
2) Modify the my. cnf file to comment out bindaddress, if any
3) Check the firewall
systemctl status iptables.service /firewalld.service And close
In addition, if you don't want to close the firewall, you can add rules. The following command is used to add
1) Make sure the firewall is started first
2) Execute commands
firewall-cmd --permanent(永久) --add-port=3306
(Default port)/tcp (protocol) responds to success
3) Execute the command to see if the rule was added successfully
firewall-cmd --permanent --query-port=3306/tcp
4) Restart the firewall to take effect
systemctl restart mariadb.service