-- 用户信息保存在数据库mysql中的user表中
--查看用户、密码、登陆方式。这里的密码是加密的
use mysql
select user authentication_string,host from user;
-- 创建用户 访问主机:%号是可以从任何机器访问,localhost只能本机访问,也可以指定ip
-- grant 权限列表 on 数据库.* to '用户名'@'访问主机' identified by '密码';
-- 数据库.*指定所有表,可以单独指定某个表
-- demo:创建一个laowang的账户,密码:123456,只能通过本地访问,只能对jing_dong数据库中的所有表进行读操作
-- 1 使用root登陆
mysql -uroot -p
-- 2 创建账户并授予权限 select是只读权限,只能查询,all privileges是所有权限
grant select on jing_dong.* to 'laowang@localhost' identified by '123456';
-- 查看用户有哪些权限
show grants for laowang@localhost;
-- 修改权限
grant 新权限名称,新权限名称 on 数据库 to 账户@主机 with grant option;
flush privileges;
-- 修改密码,使用password()函数对密码加密
-- update user set authentication_string=password("新密码") where user="用户名";
-- demo:
update user set authentication_string=password("123") where user="laowang";
flush privileges
--连接远程数据库,具有不安全性,用ssh代替
mysql -uxxx -pxxx -h19.168.1.10 -p3306
-- 要先修改mysql的配置文件:
-- vim /ect/mysql/mysql.conf.d/mysqld.conf
-- 将配置文件中的'bind-addr = 127.0.0.1'注释掉,然后重启mysql
-- 删除用户,删除后需要执行flush privileges
-- 语法1
-- drop user '用户名@主机';
drop user 'laowang@localhost';
-- 语法2
-- delete from user whre user='用户名';
delete from user where user='laowang';