Home > Database > Mysql Tutorial > How to Securely Grant Remote Access to Your MySQL Server?

How to Securely Grant Remote Access to Your MySQL Server?

Barbara Streisand
Release: 2024-12-16 11:25:10
Original
632 people have browsed it

How to Securely Grant Remote Access to Your MySQL Server?

Granting Remote Access to MySQL Server for Specific Users

In MySQL, when you create users, their access is typically limited to the local machine ('localhost'). However, you may need to grant permissions to access the database server from remote machines. This is especially useful if you have multiple workstations or servers that require access to the same database.

Granting Remote Access Using a Host Pattern

To grant remote access to a specific user, you can use the following syntax:

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%.domain.com' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
Copy after login

In this example, '%.domain.com' represents any machine in the 'domain.com' network. This grants the specified user ('username') access to all databases ('.') with the provided password.

Granting Remote Access Using IP Address or Subnet

If you cannot use a host pattern due to name resolution issues, you can grant access using the IP address or subnet of the remote machine:

GRANT ALL PRIVILEGES ON *.* TO 'username'@'192.168.1.%' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
Copy after login

In this example, '192.168.1.%' grants access to any machine with an IP address beginning with '192.168.1.'.

Note: It's important to be cautious when granting remote access to MySQL servers. Ensure that you only grant access to authorized users and limit their privileges to what is necessary.

The above is the detailed content of How to Securely Grant Remote Access to Your 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template