Home > Database > Mysql Tutorial > body text

How to Connect to a Remote MySQL Server?

DDD
Release: 2024-11-21 08:00:13
Original
503 people have browsed it

How to Connect to a Remote MySQL Server?

Connecting to a Remote MySQL Server

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
Copy after login

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';
Copy after login

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'@'%';
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template