找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
【用户权限】
use mysql; ==存数据库的用户
select host, user,password from user; ==>查看user表中有哪些用户
localhost和127.0.0.1  代表的都是本地用户==》可以通过centos和shell对数据进行修改
% 代表是具有远程访问权限的用户==》可以通过数据库客户端工具进行连接操作
1。insert into user(host, user,password) values("localhost","dcs9",password("123456"));==》往user表中增加一个dcs9的用户
2. show grants for "dcs9"@"localhost";==》查看是否有权限如下报错是没有权限
ERROR 1141 (42000): There is no such grant defined for user 'dcs9' on host 'localhost'
3. flush privileges;==》加载刷新权限
4.show grants for "dcs9"@"localhost"; ==》再次查看权限

USAGE 是没有权限的意思
5. grant select on *.* to "dcs9"@"localhost" identified by '123456';==》开始赋权
*.* 表示所有数据库里面的表数据
6. flush privileges; ==刷新加载权限
7. show grants for "dcs9"@"localhost";==再次查看权限,已具有查询权限
8. revoke all on *.* from "dcs9"@"localhost"; ==移除本地用户dcs9的所有权限

9.  grant all privileges on *.* to "root"@"%" identified by "123456";==》给远程用户root赋有所有权限
10. delete from user where user="dcs9" and host="localhost"; 删除本地访问权限的dcs9用户
11.  update user set password=password ("123456") where user ="root" and host="%"; 修改密码

连接不上:
1. 用户是否有远程访问权限
进行赋权 : grant all privileges on *.* to "root"@"%" identified by"123456";
2. 关闭防火墙
service iptables stop (liunx界面执行,部署mysql里执行)
3.检查 mysql服务是否开启
service mysqld  start

navicat 的使用
ctrl +q 新建一个窗口
ctrl +w 关闭一个窗口
单行注释: 用#号 被注释的sql语句不会被执行
多行注释:/*注释内容*/

2给表当中字段的值相同则可以进行拼接
1.普通连接(基本连接)(取aa,cc两表交集部分)
select * from aa, cc where aa.id=cc.s_id;

2.内连接(aa inner join cc 取交集部分)
select * from aa INNER JOIN cc on aa.id=cc.s_id;

3.左连接(左边表中的数据全部显示,右边表符合条件的则显示不符合条件的则填充null;以左表为基准)
select * from aa left  JOIN cc on aa.id=cc.s_id;

4.右连接 (右边表中的数据全部显示,左表符合条件的则显示不符合条件的则填充null;以右表为基准)
select * from aa RIGHT JOIN cc on aa.id =cc.s_id;

5.硬链接 --追加(2个表的字段数量必须相同)
select * from aa union select * from cc;

求张三的成绩
1.临时表
select * from aa,cc where aa.id=cc.s_id;
select t.score from (select * from aa,cc where aa.id=cc.s_id) as t WHERE NAME="zhangsan";

2.基本连接
select aa.name,cc.score from aa,cc where aa.id=cc.s_id and name="zhangsan";#---基本连接
3.嵌套方法“=”(=和in的区别,=只能是一个值,in后面可以是多给值)


select id from aa where name="zhangsan"; --先求出学号
select cc.score from cc where cc.s_id=(select id from aa where name="zhangsan");




嵌套方法"in"
select cc.score from cc where cc.s_id in(select id from aa where name="zhangsan");



求谁没参加考试?
第一种方法左连接
select * from aa left join cc on aa.id=cc.s_id;
select aa.name from aa left join cc on aa.id=cc.s_id where score is null;



第二种方法右连接
select * from cc RIGHT JOIN aa on aa.id=cc.s_id;
select name from cc RIGHT JOIN aa on aa.id=cc.s_id where score is null;



第三种方法基本连接+嵌套
select id from  aa,cc where aa.id=cc.s_id;==》先求出已参加考试的学号
select name from aa where aa.id not in(select id from  aa,cc where aa.id=cc.s_id);



第四种方法嵌套
select name from aa where aa.id not in (select s_id from cc);



















分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册