随笔分类 -  mysql

摘要:mysql排行榜写法 $sql = 'select * from (SELECT t.*, @rownum := @rownum + 1 AS rownum FROM (SELECT @rownum := 0) r, (SELECT * FROM lanchengcocmanghe_oauthinf 阅读全文
posted @ 2022-01-15 16:48 newmiracle宇宙 阅读(18) 评论(0) 推荐(0) 编辑
摘要:mysql order by用覆盖索引的方法 select dingdan from caiwuxitong_dingdanlist order by price desc 比如这个语句就应该 设置索引 顺序不能错 必须是price在前面 这样才能using index 覆盖索引排序(先是从第一个索 阅读全文
posted @ 2021-10-26 11:10 newmiracle宇宙 阅读(95) 评论(0) 推荐(0) 编辑
摘要:php不用pdo防止sql语句注入的方法 function getrepairsql($sql, $replacement, $isreturn = 0) { $count = substr_count($sql, '?'); $pattern = array_fill(0, $count, '/\ 阅读全文
posted @ 2021-10-13 09:36 newmiracle宇宙 阅读(38) 评论(0) 推荐(0) 编辑
摘要:mysql临时表是基于缓存还是基于硬盘 经过我的测试 是基于硬盘的 不是基于缓存 所以要用缓存还是用memcache引擎好 drop table if exists tablenamedd1211; create table tablenamedd1211 engine=MEMORY (select 阅读全文
posted @ 2021-10-04 19:56 newmiracle宇宙 阅读(105) 评论(0) 推荐(0) 编辑
摘要:mysql 子查询少用 用了子查询 就没有索引了 。。。所以一般用缓存代替 或者其他方法代替 阅读全文
posted @ 2021-09-30 17:38 newmiracle宇宙 阅读(43) 评论(0) 推荐(0) 编辑
摘要:mysql 临时表代替in的方法 public function infengzhuang($ziduanstr = '', $table = '',$whereziduan='',$instr = '', $wherestr = '') { $haomiao = $this->get_millis 阅读全文
posted @ 2021-09-30 11:00 newmiracle宇宙 阅读(701) 评论(0) 推荐(0) 编辑
摘要:Create temporary table new_table_name1 (Select * from aa_copy_copy); mysql创建临时表不用创建临时表结构的方法 阅读全文
posted @ 2021-09-30 09:43 newmiracle宇宙 阅读(113) 评论(0) 推荐(0) 编辑
摘要:mysql如何查询下一条数据 select * from table_a where id = (select min(id) from table_a where id > {$id}); 阅读全文
posted @ 2021-08-03 10:41 newmiracle宇宙 阅读(112) 评论(0) 推荐(0) 编辑
摘要:mysql select保留小数点的方法 select format(1,2) from moban_oauthinfo 就有2位小数点了 阅读全文
posted @ 2021-08-03 10:23 newmiracle宇宙 阅读(321) 评论(0) 推荐(0) 编辑
摘要:mysql大数据分页优化方法 SELECT * FROM product WHERE ID > =(select id from product limit 866613, 1) limit 20 主要用了覆盖索引 来获取id 阅读全文
posted @ 2021-08-03 09:32 newmiracle宇宙 阅读(48) 评论(0) 推荐(0) 编辑
摘要:mysql临时表代替in的写法 $sql = "create temporary table tmp(id int(4) primary key)"; $this->commonexecute($sql); $sql = "insert into tmp values (23), (433)"; $ 阅读全文
posted @ 2021-07-06 11:16 newmiracle宇宙 阅读(197) 评论(0) 推荐(0) 编辑
摘要:mysql临时表进行批量更新 $sql = "create temporary table tmp(id int(4) primary key,dr varchar(50))"; $this->commonexecute($sql); $sql = "insert into tmp values ( 阅读全文
posted @ 2021-07-06 11:01 newmiracle宇宙 阅读(654) 评论(0) 推荐(0) 编辑
摘要:mysql in后面语句多的处理方法 直接分批 阅读全文
posted @ 2021-06-04 09:16 newmiracle宇宙 阅读(265) 评论(0) 推荐(0) 编辑
摘要:修改mysql root 密码的方法 进入mysql数据库 update user set password=password('admin') where user = 'root'; flush PRIVILEGES 阅读全文
posted @ 2020-12-10 21:32 newmiracle宇宙 阅读(61) 评论(0) 推荐(0) 编辑
摘要:// 单条插入 for ($i = 0; $i < 1000; $i++) { $name = rand(1000, 9999); $email = rand(1000, 9999); $message = rand(1000, 9999); $insertdata = array('name' = 阅读全文
posted @ 2020-11-25 20:56 newmiracle宇宙 阅读(366) 评论(0) 推荐(0) 编辑
摘要:要保证一致性 那就是mysql和redis要保证原子性 当然保证原子性是不可能的 可以有一种择优的方法 网上说双删 我感觉双删太复杂 我不建议采取 我方案就是 1 用redis记录下准备开始 2 缓存失效 3 读取数据库 4 数据库数据写入缓存 5 用redis记录下确保执行完 就是要保证 1到5 阅读全文
posted @ 2020-11-11 10:39 newmiracle宇宙 阅读(230) 评论(0) 推荐(0) 编辑
摘要:mysql锁表需要注意的问题 有时候添加索引需要锁表 lock table t10 write; 是锁读写 lock table t10 read 是锁写 unlock tables;释放所有锁 但是注意 mysql正在读取或者正在写入的时候 禁止操作锁表 不然会死锁 所以运行锁表前 所有逻辑关闭了 阅读全文
posted @ 2020-11-10 18:08 newmiracle宇宙 阅读(194) 评论(0) 推荐(0) 编辑
摘要:mysql实现高并发计数器 因为在高并发下 set aa=aa+1要进行锁表 不然会计算错误 但是锁表了 性能就降低了 所以 计数器采用另外一种方案 CREATE TABLE `article_view`( `article_id` int(11) NOT NULL, `pond` tinyint( 阅读全文
posted @ 2020-11-03 09:03 newmiracle宇宙 阅读(701) 评论(0) 推荐(0) 编辑
摘要:redis互斥锁解决缓存雪崩问题 刚1000个人并发 突然redis缓存失效 那全部打入数据库 解决方法 就是redis写个互斥锁 缓存失效的时候 先锁住 等有缓存了 再解锁 比方说第一个人 加锁 加缓存 999个人就可以直接读取缓存了 这样就不会1000个人读取数据库了 public functi 阅读全文
posted @ 2020-10-09 17:42 newmiracle宇宙 阅读(1673) 评论(0) 推荐(0) 编辑
摘要:redis实现mysql锁的方法 $config = array( 'host' => 'localhost', 'port' => 6379, 'index' => 0, 'auth' => '3213', 'timeout' => 1, 'reserved' => null, 'retry_in 阅读全文
posted @ 2020-10-08 10:19 newmiracle宇宙 阅读(312) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示