mysql 用户分 普通用户和root用户
登录数据库
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’
使用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=’’;
用户帐号过期(5.6.6版本才有的功能)
Alter user jss password expire;
修改密码
方法1:
mysqladmin -u username -h localhost -p password ‘新密码’
方法2:(不推荐)
update mysql.user set Password=passsword(“新密码”) where user=root and host=’localhost’
flush privileges
方法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 &
版权声明:本文为博主原创文章,未经博主允许不得转载。
用户管理