Enabling Remote Connections and Obtaining Connection Details for Your MySQL Database
Prerequisites
- MySQL server installed on a Windows machine.
- Administrative access to the server.
- MySQL client tool (e.g., MySQL Workbench) for database management.
- Firewall configuration privileges.
Step-by-Step Guide
1. Edit MySQL Configuration File
- Locate the MySQL configuration file (
my.ini
). By default, it is located in the MySQL installation directory, e.g., C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
.
- Open
my.ini
in a text editor like Notepad.
- Find the line starting with
bind-address
and change its value to 0.0.0.0
. If the line doesn’t exist, add it under the [mysqld]
section:
[mysqld]
bind-address = 0.0.0.0
- Save the changes and restart the MySQL service:
net stop mysql
net start mysql
2. Grant Remote Access to a User
- Open the MySQL command line client or any MySQL client tool.
- Log in as the root user or any user with sufficient privileges:
mysql -u root -p
- Grant remote access to a user:
GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'%' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
3. Configure Windows Firewall
- Open Windows Firewall with Advanced Security (
wf.msc
).
- Click on
Inbound Rules
and then New Rule
.
- Select
Port
and click Next
.
- Select
TCP
and specify the port number 3306
.
- Choose
Allow the connection
and proceed.
- Select when the rule applies (e.g., Domain, Private, Public).
- Give the rule a name (e.g.,
MySQL Port 3306
) and finish the wizard.
4. Verify Remote Connection
- From a remote machine, use the MySQL client to connect to the MySQL server:
mysql -u user_name -h server_ip_address -p
Troubleshooting
- Ensure the MySQL server is running.
- Verify the firewall settings allow traffic on port 3306.
- Check the MySQL user has the correct privileges for remote access.
- Confirm the IP address is correctly specified in the connection command.
Obtaining Connection Details
Once you have enabled remote access and verified the connection, you will need the following details to connect your MySQL database to the web app:
- **Database Name:** The name of your database.
- **Username:** The username with remote access privileges.
- **Password:** The password for the username.
- **Server IP Address:** The IP address of your MySQL server.
- **Port Number:** The port number (default is 3306).
Ask Database