MySQL添加新用户、为用户创建数据库、为新用户分配权限

1、连接到数据库:

mysql -u root -p

  mysql -u root -h 106.14.72.xxx  -p

查看数据库列表:   show databases;

列出所有表:show tables;

切换数据库:use '数据库名';

显示数据表结构:describe 表名;

查看用户状态: select host,user from mysql.user;

2、创建用户:

允许本地 IP 访问 localhost, 127.0.0.1

create user 'test'@'localhost' identified by '123456';

允许外网 IP 访问

create user 'test'@'%' identified by '123456';

刷新: flush privileges;

3、建数据库:

create database testDB DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

4、授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限):

grant all privileges on testDB.* to test@localhost identified by '123456';

指定部分权限给一用户:

grant select,update on testDB.* to test@localhost identified by '123456';

授权test用户拥有所有数据库的某些权限:

grant select,delete,update,create,drop on *.* to test@'%' identified by '123456';

//   @'%' 表示对所有非本地主机授权,不包括localhost。

flush privileges; //刷新系统权限表

5、删除用户

Delete FROM mysql.user Where User='test' and Host='%';

删除数据库:

drop database testDB;

删除账户及权限:drop user 用户名@'%';

        drop user 用户名@ localhost; 

6、修改指定用户密码

update mysql.user set password=password('新密码') where User="test" and Host="localhost";

flush privileges;

7、退出 :exit;

 

 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值