在 MySQL 中创建新用户并授予它对一个数据库的完全访问权限

Create new user in MySQL and give it full access to one database(在 MySQL 中创建新用户并授予它对一个数据库的完全访问权限)
本文介绍了在 MySQL 中创建新用户并授予它对一个数据库的完全访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想在 MySQL 中创建一个新用户,并只授予它对一个数据库的完全访问权限,例如 dbTest,我使用类似 create database 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?

推荐答案

试试这个来创建用户:

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' 是您正在创建的用户帐户的用户名.注意:你必须在那里有单引号.'hostname' 告诉 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 中创建新用户并授予它对一个数据库的完全访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)