Mysql——查询语句备份
echo "++++++ modify log_uid start ++++++"
mysql -h$targetIp -uroot codex_log_operation -Bse "show tables;" \
| xargs -I "{}" mysql -h$targetIp -uroot codex_log_operation -e \
"alter table {} modify log_uid varchar(128) NOT NULL; \
alter table {} modify account_id bigint(64); \
select concat(server_id, '_', log_uid) from {} limit 0;\
update {} set log_uid = concat(server_id, '_', log_uid) where length(0+log_uid)=length(log_uid);"
echo "++++++ modify log_uid end ++++++"
select "重置id...";
drop procedure if exists `resetId`;
delimiter $$
create procedure resetId(In targetTabName varchar(200))
begin
select targetTabName, @baseId;
set @sqlStr=CONCAT('delete from ', targetTabName, ' where roleId not in (select id from role)');
PREPARE stmt from @sqlStr;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
set @sqlStr=CONCAT('update ', targetTabName, ' set id= id%(1<<42) +', @baseId, ', roleId= roleId%(1<<42) +', @baseId);
PREPARE stmt from @sqlStr;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
commit;
end$$
delimiter ;
SET @baseId=0;
select id, (id>>47)%(1<<11)%100, (id>>47)%(1<<11), id%(1<<42), @baseId:=(id-id%(1<<42)) from server limit 1;
select @baseId;
call resetId('activity_cat_usersave');