Mysql 用户添加、密码修改、授权等

一、数据库的连接

1:连接本地数据库(root 用户,隐藏密码)

    mysql -u root -p


2:连接本地数据库(root用户,密码为123,与-p不能有空格)

    mysql -u root -p123


3:远程连接数据库(IP为192.168.7.116,用户为ll)

    mysql -h 192.168.7.116 -P 3306 -u ll -p


4:连接指定的数据库Test(登陆进去可直接用select database()查看)

    mysql -u root -p123 -D Test


二、密码的修改

1:在没有密码的情况下

     mysqladmin -u root password


2:修改密码(在知道原密码的情况下)

     mysqladmin -u root -p password 123


3:在mysql.user表里修改(重启mysql服务或flush privileges才生效,password设置的时候不能直接password='13')

     update mysql.user set password=password('123456') where user='root' and host='localhost';


4:在mysql里修改:

     set password for ll=password('123456');


5:忘记密码

     打开配置文件 vim /etc/my.cnf 在里面添加 skip-grant-tables

 
 

三、用户添加与授权

1:create添加用户

     create user ll identified by '123456';


2:修改用户名

      rename user ll to lll;


3:在mysql的user表中直接添加用户信息

      insert into mysql.user(User,Host,Password) values('ll','localhost',password('123'));


3:  grant授权方式添加用户

     grant select,insert on lop.* to 'mm'@'localhost' identified by '123';

    
     若密码修改为空

     grant select,insert on lop.* to 'mm'@'localhost' identified by '';


4:查看用户的权限

     show grants ;   show grants for ll;


5:权限的收回

     revoke select,insert on lop.*  from 'mm'@'localhost';


四、删除用户

1:在mysql的user表中删除

     delete from mysql.user where user='ll';


     drop user 'll'@'localhost'



 
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值