MySQL用户管理:添加用户、授权、删除用户

username@host表示授权的用户及允许登录的IP地址,如localhost(本地)、%(任何远程机器)、特定IP(如192.168.51.32)。密码设置使用update mysql.user set password = password('testnewmima') where user = 'testnew' and host = '%';命令。删除用户使用drop user testnew@'%';命令。常用...
MySQL用户管理:添加用户、授权、删除用户
添加用户

以root用户登录数据库,执行命令:create user testnew identified by 'testnew';创建用户testnew,设置密码为testnew。

授权

使用grant语句授权权限,命令示例:grant all privileges on testnewDb.* to testnew@'%' identified by 'testnew';授权testnew用户testnewDb数据库的所有操作权限。

查看权限使用show grants命令,示例:show grants for 'testnew';

权限类型包括:all privileges(所有权限)、select(读取)、delete(删除)、update(更新)、create(创建)、drop(删除数据库/表)。

权限指定具体库或表,如 dbName.*、dbName.dbTable、.(所有数据库)。

username@host表示授权的用户及允许登录的IP地址,如localhost(本地)、%(任何远程机器)、特定IP(如192.168.51.32)。

密码设置使用update mysql.user set password = password('testnewmima') where user = 'testnew' and host = '%';命令。

删除用户使用drop user testnew@'%';命令。

常用命令组

创建用户并授权所有权限:create user testnew identified by 'testnew';grant all privileges on testnewDb.* to testnew@'%' identified by 'testnew';flush privileges;。

针对本地登录权限添加:grant all privileges on testnewDb.* to testnew@'localhost' identified by 'testnew';。2024-09-24
mengvlog 阅读 50 次 更新于 2025-10-30 09:20:25 我来答关注问题0
檬味博客在线解答立即免费咨询

mySQL相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部