1、 用create user语句来创建普通用户,格式
Create user username [identified by [password]‘password’][,user[identified by [password] ‘password’]]……,如果密码只是一个普通的字符串,就没有必要使用password关键字
2、 insert intomysql.user(host,user,password,ssl_cipher,x509_issuer,x509_subject)values("localhost","dafanzi",password('dafanzi'),'','','');这里必须设置后面那三项不常用的列。
3、 用GRANT语句来新建普通用户。Grant priv_typeon database.table to username [identified by [password]‘password’][,user[identified by [password] ‘password’]]……l例子:GRANT select on *.*to ‘test’@’localhost ’ identified by ‘tes3’;
删除普通用户:
1、 用drop user 删除 drop userusername [,username];
2、 用delete语句删除 delete frommysql.usr where host=”” and user=””;
所有操作执行完毕后,记得要用flushprivileges;
Root用户 修改密码
1、 用mysqladmin来 mysqladmin –u username–p password “new_password”;
需要注意一点,后面的password要用双引号包住,单引号不行。
2、 修改mysql数据库下的user表update mysql.user set password=password(“new_password”) wheruser=”username” and host=”hostname”;
3、 用set语句来修改root用户的密码set password=password(“new_password”);
Root用户修改普通用户的密码
1、 使用set 格式:set password for “username”@”hostname”=password(“new_pwd”);
修改mysql数据库下的user表 update mysql.user setpassword=password() where user=”username” and host=”hostname”;
2、 用grant语句来修改grant select on *.*to “username”@”hostname” identified by [password] “pwd”;
普通用户修改密码
1、 set password=password(‘new_pwd’);
2、 如果普通用户有执行mysqladmin命令的权限,可以用mysqladmin和上面一样,来修改
Root 用户密码丢失的解决办法
在windows下用这几种方式打开mysql(所以之前先net stop mysql 一下)
Mysqld –skip-grant-tables
Mysqld-nt –skip-grant-tables
Net start mysql –skip-grant-tables
Linux下
Mysqld_safe --skip-grant-tables user=mysql
/etc/init.d/mysql start --mysql--skip-grant-tabes
启动好mysql 服务器后在登录(因为上面设置避开了权限检查,不用密码也可以)
Mysql –u root
然后就是修改密码,再flushprivileges;就ok了
TSKILL processid | processname 杀死进程,你也可以在任务管理器中,结束进程,然后在net start mysql
权限管理
1、 授权的格式grant select ,update on*.* to “test5”@”localhost” identifiedby “test5” [
with grant option];
2、 收回权限revoke update on *.* from “test5”@”localhost”; revoke allprivileges,grant option from “test5”@”localhost”;(另外即使是revoke all privileges,grant option也要加on [*.*])
3、 查看权限select * from mysq.user;
4、 查看权限shoe grants for “root”@”localhost”;