成都10班蔡阳 发表于 2021-11-23 19:01:49

MySQL & navicat


[*]Mysql数据库新增用户和删除用户权限
[*]新增用户

1、先进入root用户中mysql数据库里面。
2、insert into user(host,user,password)values('localhost','dcs10',password('123456'));插入一个本地名为dcs10的用户,密码为123456.
3、show grants for 'dcs10'@'localhost';查看新建用户的权限(查看后发现新用户没有权限)。
4、grant select,drop,delete,update,create on *.* to 'dcs10'@'localhost' identified by '123456';给dcs10用户赋予增删改查的权限,
5、flush privileges,赋权后进行刷新

[*]删除用户权限

1、revoke all on *.* from 'dcs10'@'localhost';删除dcs10用户的权限
2、flush privileges,删除后进行刷新

[*]在创建用户的同时赋予权限

1、grant all privileges on *.* to 'dcs20'@'localhost' identified by '123456':创建一个名为dcs20,密码为123456用户,并给其赋予所有权限。
2、用select语句查看是有在user表中新建了用户
3、show grants for 'dcs20'@'localhost';查看dcs20所有的权限(发现是所有权限)。
4、delete from user where user=.........:删除用户
5、update user set password =password('654321') where user ='dcs20':将dcs20 的密码更改为654321.

注意:每次更新信息后都需要用filsh privileges去刷新数据库信息。
navicat


1、navicate连接MySQL数据库:
   注:先要在mysql数据库中创建一个具有远程控制权限的root用户,如果连接不上,就需要在linux界面 用命令关闭防火墙。
2、多表查询:
1、内连接:(innerjoin)对于两个表中有字段相同,就可以通过内连接进行拼接;
      例:select * from aa INNER JOIN cc on aa.id=cc.s_id #内连接查询
2、左连接:以左边的表为主,对于不符合条件的数据显示null
       例:select * from aa LEFT JOIN cc on aa.id=cc.s_id #左连接查询
3、右连接:以右边的表为主,对于不符合条件的数据显示null
       例:select * from aa RIGHT JOIN cc on aa.id=cc.s_id#右连接查询
4、基本连接:对于两个表中有字段的值相同就可以基本连接进行拼接
       例:select * from aa,cc where aa.id=cc.s_id;#先做基本连接
5、硬链接:2个表中的字段数量需要相同
      例:select * from aa unionselect * from cc
6、临时表:(通过sql语句查出来的显示表都可以作为临时表)
例:查张三的成绩
   先将2张表做拼接
select* from aa,cc where aa.id=cc.s_id
select name,score form (select* from aa,cc where aa.id=cc.s_id )t where name='zhangsan'
7、用嵌套=方法
例:查张三的成绩
select id from aa where name='zhangsan';
select score from cc where cc.s_id=(select id from aa where name='zhangsan')
8、嵌套in方法
例:查张三的成绩
select id from aa where name='zhangsan';
select score from cc where cc.s_id in (select id from aa where name='zhangsan')
9、用基本连接方法
select name,score from aa,cc where aa.id=cc.s_id and name='zhangsan'






页: [1]
查看完整版本: MySQL & navicat