In order to connect to a MySQL server on another PC in your local network, you need to follow a few steps.
The first step is to make sure that the MySQL server is configured to allow connections from other computers. To do this, you need to open the MySQL configuration file (usually located at /etc/my.cnf) and add the following line:
bind-address = 0.0.0.0
This will tell the MySQL server to listen on all network interfaces, including those that are not directly connected to the local machine.
Once you have made this change, you need to restart the MySQL server.
The next step is to create a user account on the MySQL server that will be used to connect from the remote computer. To do this, you can use the following command:
CREATE USER 'remote_user'@'%' IDENTIFIED BY 'remote_password';
Be sure to replace 'remote_user' and 'remote_password' with the actual username and password that you want to use.
Once you have created the user account, you can grant it the necessary privileges to access the database that you want to connect to. To do this, you can use the following command:
GRANT ALL PRIVILEGES ON database_name.* TO 'remote_user'@'%';
Be sure to replace 'database_name' with the actual name of the database that you want to grant access to.
Once you have granted the necessary privileges, you can connect to the MySQL server from the remote computer using the following command:
mysql -u remote_user -h server_ip -p
Be sure to replace 'remote_user' with the username that you created, 'server_ip' with the IP address of the MySQL server, and 'password' with the password that you created for the user.
If you are still having problems connecting to the MySQL server, please check the error messages that are being displayed. These messages will usually give you a good idea of what is wrong.
The above is the detailed content of How to Connect to a Remote MySQL Server?. For more information, please follow other related articles on the PHP Chinese website!