在MySQL中创建新用户并授予其对一个数据库的完全访问权限 [英] Create new user in MySQL and give it full access to one database

查看:286
本文介绍了在MySQL中创建新用户并授予其对一个数据库的完全访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MySQL中创建一个新用户,并授予其对我使用create database dbTest;之类的命令创建的一个数据库(例如dbTest)的完全访问权限. MySQL命令将执行该操作吗?

I want to create a new user in MySQL and give it full access only to one database, say dbTest, that I create with a command like create database dbTest;. What would be the MySQL commands to do that?

推荐答案

尝试使用此方法创建用户:

Try this to create the user:

CREATE USER 'user'@'hostname';

尝试使用此方法授予它对数据库dbTest的访问权限:

Try this to give it access to the database dbTest:

GRANT ALL PRIVILEGES ON dbTest.* To 'user'@'hostname' IDENTIFIED BY 'password';

如果您在同一台计算机上运行访问MySQL的代码/站点,则主机名将为localhost.

If you are running the code/site accessing MySQL on the same machine, hostname would be localhost.

现在,分解.

GRANT-这是用于创建用户并授予数据库,表等权限的命令.

GRANT - This is the command used to create users and grant rights to databases, tables, etc.

ALL PRIVILEGES-这告诉它用户将具有所有标准特权.但是,这不包括使用GRANT命令的特权.

ALL PRIVILEGES - This tells it the user will have all standard privileges. This does not include the privilege to use the GRANT command however.

dbtest.*-这指示MySQL将这些权限应用于在整个dbtest数据库中使用.您可以根据需要将*替换为特定的表名或存储例程.

dbtest.* - This instructions MySQL to apply these rights for use in the entire dbtest database. You can replace the * with specific table names or store routines if you wish.

TO 'user'@'hostname'-'user'是您正在创建的用户帐户的用户名.注意:您必须在其中使用单引号. 主机名"告诉MySQL用户可以连接的主机.如果只希望从同一台计算机上使用它,请使用localhost

TO 'user'@'hostname' - 'user' is the username of the user account you are creating. Note: You must have the single quotes in there. 'hostname' tells MySQL what hosts the user can connect from. If you only want it from the same machine, use localhost

IDENTIFIED BY 'password'-如您所料,这将设置该用户的密码.

IDENTIFIED BY 'password' - As you would have guessed, this sets the password for that user.

这篇关于在MySQL中创建新用户并授予其对一个数据库的完全访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆