linux_ysql_sql语言DCL

本文命令总结

Create user [email protected]’localhost’ identified by ‘[email protected]’; 创建本地用户并指定密码
Selete * from mysql.user\G 查看现有的用户
Drop user [email protected]’localhost’; 删除用户
set password=password(‘[email protected]’); 数据库内修改密码为[email protected]
vim /etc/my.cnf 加入Skip-grant-tables 忘记密码跳过验证
update mysql.user set authentication_string =password(‘[email protected]’) where user=‘root’ and host=‘localhost’; 免密进入到数据库更改密码数据
Mysqladmin -uroot -p’[email protected]’ password ‘[email protected]’ shell命令修改密码
mysql -P 3306 -uroot -p’[email protected]’ -e’show databases’ -h localhost 端口 用户 密码 直接显示查询结果 登录主机 跟数据库名直接登录进入该数据库

grant all on haha.* to ‘zhaosi’@’%’ identified by ‘[email protected]’; 把haha数据库内的所有表授权所有权限(除授权权限)给网络上任意ip的zhaosi用户 登录本机mysql的密码为[email protected]
revoke all on haha.* from [email protected]’%’; 去除用户赵四对haha数据库的所有权限

DCL 数据控制语言

Mysql用户管理

创建用户
linux_ysql_sql语言DCL
Create user [email protected]’localhost’ identified by ‘[email protected]’; 创建登陆方式为本地的用户赵四,密码为[email protected]。localhost也可以换成指定ip或ip段的用户登录

Selete * from mysql.user\G 查看用户是否创建成功
linux_ysql_sql语言DCL

Mysql -uzhaosi -p’[email protected]’ 退出mysql的root用户使用刚才创建的zhaosi用户登录

linux_ysql_sql语言DCL

删除用户

Drop user [email protected]’localhost’; 删除用户
Select user from mysql.user; 查看用户是否删除
linux_ysql_sql语言DCL
linux_ysql_sql语言DCL

修改密码

1 登陆进mysql进行修改
Set password=password(‘[email protected]’); 修改密码为[email protected] 退出重新用新密码进入
linux_ysql_sql语言DCL

2 在linux系统中进行修改密码
Mysqladmin -uroot -p’[email protected]’ password ‘[email protected]’ 修改密码为[email protected]

linux_ysql_sql语言DCL

3 root用户忘记linux密码如何更改
打开Vim /etc/my.cnf
加入一行命令 跳过验证
Skip-grant-tables
linux_ysql_sql语言DCL

Systemctl restart mysqld 重启mysql服务
输入mysql直接进入数据库

update mysql.user set authentication_string =password(‘[email protected]’) where user=‘root’ and host=‘localhost’; 在mysql数据库中的user表中更改数据 更改root用户的密码为[email protected],退出数据库 到my.cnf文件中取消掉跳过验证命令 。保存重启mysql服务

登录mysql的选项

mysql -P 3306 -uroot -p’[email protected]’ -e’show databases’ -h localhost
-P 登录端口 默认3306 可不加
-e 不进入mysql执行查询命令
-h 登录主机 可以指定为网络主机

linux_ysql_sql语言DCL

mysql -P 3306 -uroot -p’[email protected]’ mysql 直接登录进mysql库内

linux_ysql_sql语言DCL

Mysql授予权限

创建用户create user zh[email protected]’%'identified by ‘[email protected]’;
用于测试权限
退出root账户使用zhaosi登录数据库
Mysql -uroot -p’[email protected]’;
登录后查看不了所有的数据

linux_ysql_sql语言DCL

进入root用户
grant all on haha.* to ‘zhaosi’@’%’ identified by ‘[email protected]’; 把haha数据库内的所有表授权所有权限(除授权权限)给网络上任意ip的zhaosi用户 登录本机mysql的密码为[email protected]

linux_ysql_sql语言DCL

重新进入zhaosi查看
linux_ysql_sql语言DCL

zhaosi已经有了对haha的权限

mysql权限回收

查看权限
Show grants\G
Show grants for [email protected]‘%’\G

linux_ysql_sql语言DCL

revoke all on haha.* from [email protected]’%’; 去除用户赵四对haha数据库的所有权限。
也可以直接删除 zhaosi用户