连接navicat
a.满足条件
1.正确账号、密码
2.输入数据库端口号:3306-3309
3.输入ip
4.重启数据库
5.关闭防火墙
6.账号%权限
b.步骤
1.进入数据库 use mysql;
2.查询用户 select host,user from user;
3.创建名为x的用户
insert into user(host,user,password)values('localhost','x',password('123456'));
4.创建用户后进行授权
grant select,delete on *.* to 'me'@'localhost' identified by '123456';
5.查看指定用户有哪些权限
show grants for ‘me'@‘localhost’;
6.取消用户的权限
revoke all on *.* from ‘me’@‘localhost’;
7.改用户密码
update user set password=password(‘123456’) where user=‘x’;
8.删除用户
delete from user where user=‘x’ and host=‘localhost’;
多表查询的方法(重点)
a.姓名表 c.成绩表
id name sid score
1 A 1 100
2 B 2 20
3 C 3 30
1.多表的条件:必须要有相同的数据
2.有哪些方法可以把表和表进行关联
①基本连接
select * from a,c where a.id=c.sid;
select * from a,c where id=sid;
此种方法只能找出两个表中都有的数值
②内链接
select * from a inner join c on a.id=c.sid;
结果出来与基本连接一致,只能显示两个表中都有的数值
③左连接:左边的表为主表,右边的表为子表(主表全部显示,如子<主,则
缺失位补null;如子>主,则只显示主) left join on
select * from a left join c on a.id=c.sid;
select * from a left join c on id=sid;
④右连接:右的表为主表,左边的表为子表(主表全部显示,如子<主,则缺
失位补null;如子>主,则只显示主) right join on
select * from a right join c on a.id=c.sid;
select * from a right join c on id=sid;
不管左右连接,a都在左边
问题:左右连接的区别?
右连接是以右表为主表,左连接是以左表为主表;如果主表大于子表,则缺失子表部分补null,如果子表大于主表,则只显示主表。
⑤union连接
select * from a union select * from c;
|
|