Home >Database >Mysql Tutorial >How to Create a MySQL User with Restricted Access to a Single Database?
MySQL user security management: restricting single database access permissions
Database security is critical and creating user accounts with specific permissions is a best practice. This effectively prevents unauthorized access and data modification. This article will demonstrate how to create a MySQL user that can only access the database named dbTest
.
Create User
Create a new user using the following command:
<code class="language-sql">CREATE USER '用户名'@'主机名';</code>
Replace 用户名
with the user name you want, and 主机名
with the hostname or IP address of the server the user is connected to.
Give database permissions
After the user is created, use the following command to give it permission to access the dbTest
database:
<code class="language-sql">GRANT ALL PRIVILEGES ON dbTest.* TO '用户名'@'主机名' IDENTIFIED BY '密码';</code>
ALL PRIVILEGES
Grants user dbTest
all standard permissions on the database. To further restrict access, you can replace *
with a specific table name or stored procedure. 主机名
Specify the host where the user can connect to the database. 密码
Set the user's password.
Detailed explanation of commands
dbTest
database. Through the above steps, you can create a MySQL user that is limited to specific database access, thereby achieving safer and more granular database management.
The above is the detailed content of How to Create a MySQL User with Restricted Access to a Single Database?. For more information, please follow other related articles on the PHP Chinese website!