mysql基本操作
MySQL5.7 常用用户操作
1. 新建用户
create user 'username'@'host' identified by 'password';
例子:
create user 'user'@'localhost' identified by '123456';create user 'user'@'localhost' identified by '';
username : 你将创建的用户名
host : 指定该用户在哪个主机上可以登陆,此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录,如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录;也可以指定某台机器可以远程登录;
password : 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器。
MySQL5.7 mysql.user表password字段改为 authentication_string;
2. 授权
grant privileges on databasename.tablename to 'username'@'host';
privileges : 用户的操作权限,如SELECT , INSERT , UPDATE 等。如果要授予所的权限则使用ALL。
databasename : 数据库名
tablename : 表名
如果要授予该用户对所有数据库和表的相应操作权限则可用*表示, 如*.*.
## 赋予user对数据库store下的所有表的查看和增添权利grant select, insert on store.* to 'user'@'localhost';
3. 创建用户时授权
grant all privileges on store.* to user@'%' identified by '123456';flush privileges;
4. 设置与更改用户密码(root)
update mysql.user set authentication_string=password("新密码") where User="test" and Host="localhost";
flush privileges;
5. 撤销用户权限
## 具体信息可以用命令show grants for 'username'@'host'; 查看. revoke privilege on databasename.tablename from 'username'@'host';
6. 删除用户
drop user 'username'@'host';
7. 查看用户的授权
show grants for user@localhost;
8. 显示当前用户信息
select user();
9. 重置root密码
在my.cnf的[mysqld]字段加入skip-grant-tables,然后重启mysql服务,这时的mysql不需要密码即可登录数据库。然后进入mysql:

浙公网安备 33010602011771号