签到成功

知道了

CNDBA社区CNDBA社区

用户管理

2018-01-06 21:03 3778 1 原创 mysql
作者: tianxiadishi

mysql 用户分 普通用户和root用户http://www.cndba.cn/tianxiadishi/article/2550

http://www.cndba.cn/tianxiadishi/article/2550
http://www.cndba.cn/tianxiadishi/article/2550

登录数据库
mysql -help
-h 主机名
-u 用户名
-p 密码
-P 端口号
数据库名
-e 执行Sql语句

例:
mysql -uroot -pciscoh3c yhc
select database(),schema();

创建普通用户(密码一定要用单引号)
使用create user创建用户
create user ‘wh01’@’%’ identified by ‘wh01’
create user ‘wh01’@’192.168.1.%’ identified by ‘wh01’ —允许某一网段的地址访问
Create user jss;
Create user jss identified by ‘jss01’http://www.cndba.cn/tianxiadishi/article/2550http://www.cndba.cn/tianxiadishi/article/2550

使用grant方式创建用户
Grant select on jssdb. to jss_02@’%’ identified by ‘jss02’
grant all privileges on
.* to wh@’localhost’ identified by ‘wh’ with grant option;

删除用户
drop user ‘wh01’@’localhost’,’wh02’@’%’;
delete from mysql.user where host=’hostname’ and user=’username’;

删除匿名帐号
对于user表中的user字段为空字符串,这会允许任何人在命令提示符下输入:mysql命令就直接连接到数据库,
select user,host from user where user=’’;
delete from user where user=’’;

http://www.cndba.cn/tianxiadishi/article/2550

用户帐号过期(5.6.6版本才有的功能)
Alter user jss password expire;

http://www.cndba.cn/tianxiadishi/article/2550

修改密码
方法1:
mysqladmin -u username -h localhost -p password ‘新密码’http://www.cndba.cn/tianxiadishi/article/2550

方法2:(不推荐)
update mysql.user set Password=passsword(“新密码”) where user=root and host=’localhost’
flush privileges http://www.cndba.cn/tianxiadishi/article/2550http://www.cndba.cn/tianxiadishi/article/2550

方法3:
set password=password(“ciscoh3c”);//修改root的密码
set password for ‘wh01’@’%’=password(‘ciscoh3c’);//使用root帐号修改其它用户的密码
Set password for jss=password(‘newpassword’)
flush privileges

方法4:
grant usage on . to ‘wh01’@’%’ identified by ‘newpassword’ //使用grant语句修改普通用户密码

root用户密码丢失的解决方法(通用)
使用-skip-grant-tables选项启动数据库,此时不加载权限判断,任何用户都能访问数据库
如果忘记了MySQL root密码,可以用以下方法重新设置:
1.结束mysql服务;
systemctl stop mysql
或者
ps -e|grep mysql
killpid….
2.用以下命令启动MySQL,以不检查权限的方式启动;
mysqld_safe —skip-grant-tables —skip-networking &
3.重新开启一个窗口,然后用空密码方式使用root用户登录 MySQL;
MySQL -u root
4.修改root用户的密码;
MySQL> update mysql.user set password=PASSWORD(‘wh870329’) where User=’root’;
MySQL> flush privileges;
MySQL> quit
5.关闭mysql,重新启动,就可以使用新密码登录了。
mysqladmin shutdown
mysqld_safe &

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户管理

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
tianxiadishi

tianxiadishi

关注
  • 17
    原创
  • 0
    翻译
  • 3
    转载
  • 14
    评论
  • 访问:110234次
  • 积分:96
  • 等级:注册会员
  • 排名:第31名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ