CentOS 7是一種非常流行的Linux操作系統,作為Web服務器,它通常需要將MySQL設置為可連接。在此過程中,您將需要進行以下幾個步驟:
步驟1:安裝mysql-server
sudo yum install mysql-server
步驟2:啟動mysql服務并設置其自動啟動
sudo systemctl start mysqld
sudo systemctl enable mysqld
步驟3:設置root用戶的密碼
sudo mysql_secure_installation
步驟4:打開MySQL服務器的防火墻端口
sudo firewall-cmd --permanent --zone=public --add-service=mysql
sudo firewall-cmd --reload
步驟5:開啟遠程訪問
在/etc/my.cnf配置文件中添加以下內容:
[mysqld]
bind-address = 允許遠程訪問的IP
重啟MySQL服務:
sudo systemctl restart mysqld
到此為止,您的MySQL服務器應該已經可以遠程訪問了。不過,為了保證安全性,建議您在/etc/my.cnf文件中禁用遠程root用戶登錄:
[mysqld]
bind-address = 允許遠程訪問的IP
skip-networking
skip-grant-tables
[client]
# password = your_password
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 16M