mysql中创建账号的关键字是

mysql中创建账号的关键字是,第1张

1.CREATE USER

CREATE USER user [IDENTIFIED BY [PASSWORD] 'password']

[, user [IDENTIFIED BY [PASSWORD] 'password']] ...

CREATE USER用于创建新的MySQL账户。要使用CREATE USER,您必须拥有mysql数据库的全局CREATE USER权限,或拥有INSERT权限。对于每个账户,CREATE USER会在没有权限的mysql.user表中创建一个新记录。如果 账户已经存在,则出现错误。

使用自选的IDENTIFIED BY子句,可以为账户给定一个密码。user值和 密码的给定方法和GRANT语句一样。特别是,要在纯文本中指定密码,需忽略PASSWORD关键词。要把 密码指定为由PASSWORD()函数返回的混编值,需包含关键字PASSWORD。

2.使用GRANT语句

最好的方法是使用GRANT语句,因为这样更精确,错误少。从MySQL 3.22.11起提供了GRANT;它的主要用途是来给帐户授权的,但也可用来建立新帐户并同时授权。注意:当mysql运行于no_auto_create_user时要提供新建用户的密码,否则不能创新用户。

下面的示例说明如何使用MySQL客户端程序来设置新用户。

首先,使用MySQL程序以MySQL root用户来连接服务器:

shell>MySQL --user=root MySQL

如果你为root账户指定了密码,还需要为该MySQL命令和本节中的其它命令提供--password或-p选项。

以root连接到服务器上后,可以添加新账户。下面的语句使用GRANT来设置四个新账户:

mysql>GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'

->IDENTIFIED BY 'some_pass' WITH GRANT OPTION

mysql>GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'

->IDENTIFIED BY 'some_pass' WITH GRANT OPTION

mysql>GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost'

mysql>GRANT USAGE ON *.* TO 'dummy'@'localhost'

用GRANT语句创建的账户有下面的属性:

· 其中两个账户有相同的用户名monty和密码some_pass。两个账户均为超级用户账户,具有完全的权限可以做任何事情。一个账户 ('monty'@'localhost')只用于从本机连接时。另一个账户('monty'@'%')可用于从其它主机连接。请注意monty的两个账户必须能从任何主机以monty连接。没有localhost账户,当monty从本机连接时,mysql_install_db创建的localhost的匿名用户账户将占先。结果是,monty将被视为匿名用户。原因是匿名用户账户的Host列值比'monty'@'%'账户更具体,这样在user表排序顺序中排在前面。(user表排序的讨论要参考mysql手册)。

· 一个账户有用户名admin,没有密码。该账户只用于从本机连接。授予了RELOAD和PROCESS管理权限。这些权限允许admin用户执行mysqladmin reload、mysqladmin refresh和mysqladmin flush-xxx命令,以及mysqladmin processlist。未授予访问数据库的权限。你可以通过GRANT语句添加此类权限。

· 一个账户有用户名dummy,没有密码。该账户只用于从本机连接。未授予权限。通过GRANT语句中的USAGE权限,你可以创建账户而不授予任何权限。它可以将所有全局权限设为'N'。假定你将在以后将具体权限授予该账户。

MySQL 5.7 新增默认账号 mysql.session和mysql.syshttps://www.jianshu.com/p/427cac0d8763Privileges Supported by MySQLhttps://dev.mysql.com/doc/refman/5.7/en/grant.htmlMySQL 5.7 Reference Manual/Reserved Accountshttps://dev.mysql.com/doc/refman/5.7/en/reserved-users.htmlWhat are mysql.session@localhost and mysql.sys@localhost user accounts good for?https://stackoverflow.com/questions/46149220/what-are-mysql-sessionlocalhost-and-mysql-syslocalhost-user-accounts-good-forOne part of the MySQL installation process is data directory initialization (see  Section 2.10.1, “Initializing the Data Directory” ).  During data directory initialization, MySQL creates user accounts that should be considered reserved:'root'@'localhost : Used for administrative purposes. This account has all privileges and can perform any operation. Strictly speaking, this account name is not reserved, in the sense that some installations rename the root account to something else to avoid exposing a highly privileged account with a well-known name.'mysql.sys'@'localhost' : Used as the DEFINER for  sys  schema objects. Use of the mysql.sys account avoids problems that occur if a DBA renames or removes the root account. This account is locked so that it cannot be used for client connections.'mysql.session'@'localhost' : Used internally by plugins to access the server. This account is locked so that it cannot be used for client connections.用于sys schema中对象的定义。使用mysql.sys用户可避免DBA重命名或者删除root用户时发生的问题。该用户已被锁定,客户端无法连接。插件内部使用来访问服务器。该用户已被锁定,客户端无法连接。root账号,其用于管理。该用户拥有所有权限,可执行任何 *** 作。 root是MySQL的特权账号,这个众所周知,也带来安全隐患,建议将root账号禁用或者删除,新建一个特权账号用于管理。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/8415475.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-16
下一篇 2023-04-16

发表评论

登录后才能评论

评论列表(0条)

保存