How to grant remote access permissions to mysql server for user?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Granting remote MySQL access is a two-part task: MySQL must allow a user from a non-local host, and the server itself must accept incoming connections on port 3306. Many setups fail because only one side is configured.
Create or Update a User for a Remote Host
In MySQL, accounts are identified by both user name and host. That means 'appuser'@'localhost' is a different account from 'appuser'@'192.0.2.10' or 'appuser'@'%'.
The safest pattern is to create a user for a specific host:
If you truly need access from anywhere, % is the wildcard host:
Use % cautiously. It is convenient for testing and risky for production unless network controls are strong.
Make MySQL Listen for Remote Connections
Even with the right grants, MySQL may still listen only on the loopback interface. Check the MySQL configuration file, often one of these:
- '
/etc/mysql/mysql.conf.d/mysqld.cnf' - '
/etc/mysql/my.cnf' - '
/etc/my.cnf'
Look for bind-address. For broad remote access, it is often set like this:
Then restart MySQL:
or on some systems:
If the server should accept connections only on one private interface, use that IP instead of 0.0.0.0.
Open the Network Path
MySQL user grants are not enough if the operating system firewall or cloud firewall blocks the port. On Linux with ufw, for example:
In cloud environments, also check security groups, VPC firewall rules, or managed database network policies.
You can confirm the server is listening with:
Test From the Remote Machine
From the client machine, try:
If the connection fails, the error message is usually informative:
- '
Access deniedpoints to account, host, or password issues.' - '
Can't connectpoints to networking, bind address, or firewall issues.'
Treat those as different classes of problem.
Prefer Principle of Least Privilege
Avoid GRANT ALL PRIVILEGES ON *.* unless the account truly needs server-wide administration. Application accounts usually need only a limited set of privileges on one database.
A tighter production grant looks like this:
This keeps remote compromise from turning into full-server compromise.
Common Pitfalls
The most common mistake is granting privileges to 'user'@'localhost' and expecting remote clients to use that account. Host is part of the account identity.
Another problem is using the correct grant but leaving bind-address on 127.0.0.1. In that case MySQL is not reachable from outside the host at all.
Developers also forget the firewall layer. MySQL can be configured correctly and still remain unreachable because the network blocks 3306.
Finally, avoid exposing a remote MySQL port to the public internet unless you have no better option. A VPN, bastion host, SSH tunnel, or private network is usually safer.
Summary
- Remote MySQL access requires both a matching
'user'@'host'account and an open network path. - Create the remote user explicitly with
CREATE USERandGRANT. - Configure MySQL to listen on the right interface with
bind-address. - Open port
3306only for trusted source addresses when possible. - Prefer least-privilege grants and private network access over wide-open exposure.
Related reading
- How to group nearby latitude and longitude locations stored in SQL
- How to handle consensus in a decentralized event sourced database?
- How to handle data migrations in distributed microservice databases
- How to handle database migrations in Spring Boot with Hibernate?
- How to handle database migrations with Kubernetes and Skaffold
- How to handle many to many in DynamoDB
- How to handle SQLAlchemy Connections in ProcessPool?
- How to handle Transaction in CosmosDB - All or nothing concept

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.