MySQL在windows环境下创建用户名和密码

1、通过cmd进入MySQL的bin目录下:
在这里插入图片描述
2、通过root账号进入数据库

mysql -u root -p123456

在这里插入图片描述
3、创建新用户,并授权该用户可以操作的数据库和表

grant all privileges on 数据库名.表名 to '用户名'@'主机名' identified by '密码' with grant option;
flush privileges;

数据库名:如果为*,表示所有数据库

表名:如果为*,表示所有表

*.*表示root权限,即满权限

主机名:localhost表示仅允许本地连接,%表示本地和远程均可连接

flush privileges;表示刷新权限,使授权生效

所以允许远程连接的时候可以使用:

grant all privileges on *.* to 'root'@'%' identified by 'root账号密码' with grant option;

比如我们新建test用户,授予该用户的权限是仅能操作test_database数据库,密码‘123’

grant all privileges on test_database.* to 'test'@'%' identified by '123' with grant option;

4、如何修改用户密码

  • 使用root账号登陆
  • 使用mysql数据库
use mysql;
  • 查看user表
select host,user,authentication_string from user;

结果:

+-----------+------------------+-------------------------------------------+
| host      | user             | authentication_string                     |
+-----------+------------------+-------------------------------------------+
| localhost | root             | *6C2FC1038AB41E3B2B6D85B409E0F2B9C11BC8D3 |
| localhost | mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | debian-sys-maint | *E73AA584982C771D0F8B40367F92049530E668D4 |
| %         | root             | *6C2FC1038AB41E3B2B6D85B409E0F2B9C11BC8D3 |
| %         | test             | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+-----------+------------------+-------------------------------------------+
  • 修改用户密码:
update user set authentication_string = password(‘新密码’) where user = '用户名' and host = '主机名';

password()为mysql自身的一个加密函数

以修改test用户密码为’456’为例

update user set authentication_string = password('456') where user = 'test' and host = '%'

5、如何撤销用户权限

revoke all on 数据库名.表名 from '用户名'@'主机名';

6、删除用户

drop user '用户名'@’主机名‘;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值