mysql 笔记

看了网上燕十八的视频,自己做的笔记

触发器:

create tigger t1
before
insert 
on t_user
for each row
begin


#具体的业务
new.xx,old.xx 

end


2、存储过程
create procedure pName(in a,out b,inout c)
begin


end;


//调用
set @inoutValue =1;
call pName(1,@outvalue,@inoutValue );

 



3、游标:


create procedure pName(in a,out b,inout c)
begin
 declare row_a int;
 declare row_b int;
 
 declare cursorName cursor for select a ,b from t_user;
 
open cursorName;
declare you int default 1;
declare exit handler for NOT FOUND set you :=0;
//循环
fetch cursorName into row_a,row_b;
repeat
--写具体的sql,例如
select row_a,row_b
fetch cursorName into row_a,row_b; 
until you =0 end repeat;
close cursorName
  
end;




--另外一种游标循环(实测)
create procedure pName( )
begin
 declare row_id int;
 declare row_userId int;
 declare row_newGId int; 


-- 遍历数据结束标志
  DECLARE done INT DEFAULT FALSE;


 declare groupCursor cursor for SELECT a.id, c.ID userId,c.GROUP_ID newGId FROM t_ct_cus_dist a INNER JOIN t_ct_customer b ON a.cus_id = b.id INNER JOIN t_sys_user c ON b.cons_id = c.ID WHERE a.group_id != c.GROUP_ID ;    

  -- 将结束标志绑定到游标
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; 


open groupCursor;

 -- 开始循环
  read_loop: LOOP
    -- 提取游标里的数据,这里只有一个,多个的话也一样;
    FETCH groupCursor INTO  row_id,row_userId,row_newGId;
    -- 声明结束的时候
    IF done THEN
      LEAVE read_loop;
    END IF;
     
  update t_ct_cus_dist set group_id = row_newGId where id = row_id;


  END LOOP;


end

 

--权限表
//链接权限
update use set host='ip' where user='root'


flush privileges; --冲刷权限


操作权限 
grant[权限1,权限2,权限3]  privileges on *.* to user@"host" identified by 'password'
常用权限:all,select ,create,drop insert update ,delete


grant[all] on *.* to lisi@"192.168.1.%" identified
//收回权限
revoke [all] on *.* to lisi@"192.168.1.%" identified 


在db级别权限控制


revoke [all] on 库名.* to lisi@"192.168.1.%" identified 


 
 --主从复制 
 binlog
 
 主:
 修改mysqld
 #给服务器起一个独特的id
 server-id=121(建议ip后三位)
 #声明二进制日志的文件为mysql.bin.xxx
 log-bin=mysql-bin
 #指定日志格式 mixed/row/statement
 binlog-format=mixed
 
 从:
 修改mysqld
#给服务器起一个独特的id
 server-id=122(建议ip后三位) 
 //同时开启备份,为了方便数据丢失之后的恢复
log-bin=mysql-bin
binlog-format=mixed


relay-log=mysql-relay
 
 
主授权;
grant replication client,replication slave on *.* to rep@"192.168.1.%" identified "rep"
flush privileges;
 
从服务器:
change master to
master_host ="192.168.1.121"
master_user="rep"
master_password="rep"
master_log_file="mysql-bin.000001"
master_log_pos=348


start slove;


 
//查看当前binlog
show master status ; 


原理:
主从分离
主:
mixed/row/statement
statement:2进制记录执行语句,如update
row:2进制记录记录的是磁盘变化
mixed:混合的,由熊根据语句,来决定




 





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值