mysql

Mysql - dynamic SQL not allowed in trigger

六眼飞鱼酱① 提交于 2021-02-10 20:35:29
问题 I want to create a trigger with dynamic SQL where I get a column name from a variable. Here is my simplified mysql schema: CREATE TABLE products (id int); INSERT INTO products VALUES (1),(2); CREATE TABLE attribute_values (product_id int, `key` varchar(100), value varchar(100)); INSERT INTO attribute_values VALUES ( 1, 'title', 'Orange'), ( 1, 'code', 'O125'), ( 2, 'title', 'Pizza'); CREATE TABLE product_attributes SELECT products.id, MAX(CASE WHEN attribute_values.key = 'title' THEN

“Row cannot be located for updating” error [another]

流过昼夜 提交于 2021-02-10 20:22:57
问题 I'm working with Delphi (XE3) and need to connect to a MySQL database. I'm having a strange problem that seems quite common but I still haven't entirely solved this problem. traditional solutions include: setting "Update Criteria" to adCriteriaKey. ensure your table has a primary key (and tell the ADO Table about it) problem 1: start the application, execute the code: if the new value happens to match what's already in the database, I get the error at position "B". problem 2: start the

“Row cannot be located for updating” error [another]

感情迁移 提交于 2021-02-10 20:21:52
问题 I'm working with Delphi (XE3) and need to connect to a MySQL database. I'm having a strange problem that seems quite common but I still haven't entirely solved this problem. traditional solutions include: setting "Update Criteria" to adCriteriaKey. ensure your table has a primary key (and tell the ADO Table about it) problem 1: start the application, execute the code: if the new value happens to match what's already in the database, I get the error at position "B". problem 2: start the

How to check if element exists in database and return a warning message?

落爺英雄遲暮 提交于 2021-02-10 19:52:26
问题 I have a case where I am importing a spreadsheet of items, and when inserting I need to check for each item if already exists (either by serial_no or serial_imei) and then for each that EXISTS I need to inform the user when the submission is done with a message such as: "Item with serial no 123456 was already found in database". Here is the way I am inserting: $stmt = $db->prepare("INSERT INTO devices (serial_imei,serial_no) VALUES (?,?)"); for ($i = 0; $i < $min; $i++) { $stmt->bind_param(

mysql - join first and last records by group type?

本小妞迷上赌 提交于 2021-02-10 19:46:43
问题 With a table like: idx type dat 0 a foo1 1 b foo2 2 c foo3 3 a foo4 4 b foo5 5 c foo6 6 a foo7 7 b foo8 8 c foo9 How can i get the first and last data of each type: for example: a foo1 foo7 b foo2 foo8 c foo3 foo9 I have tried this query, but its way to slow, even with indexes on idx and type: select mins.type, mins.dat, mytable.dat from mytable --get the maximums inner join (select max(idx) as maxidx from mytable group by type) as a on a.maxidx = mytable.idx --join the maximums to the

mysql - join first and last records by group type?

梦想的初衷 提交于 2021-02-10 19:46:37
问题 With a table like: idx type dat 0 a foo1 1 b foo2 2 c foo3 3 a foo4 4 b foo5 5 c foo6 6 a foo7 7 b foo8 8 c foo9 How can i get the first and last data of each type: for example: a foo1 foo7 b foo2 foo8 c foo3 foo9 I have tried this query, but its way to slow, even with indexes on idx and type: select mins.type, mins.dat, mytable.dat from mytable --get the maximums inner join (select max(idx) as maxidx from mytable group by type) as a on a.maxidx = mytable.idx --join the maximums to the

MySQL最流行的版本,是不是5.6?

送分小仙女□ 提交于 2021-02-10 18:51:07
MySQL 5.6 ,是现在 最流行 的版本。 很遗憾有一些功能一直没有,例如: (1)哈希索引; (2)T-tree索引; (3)原生高可用; (4)auto-sharding; (5)... 画外音:你最希望看到支持什么特性? 但,5.6版本中,InnoDB有些有意思的特性,或许是大伙还不清楚,今天简单和大家介绍一下。 画外音:大家应该都是用InnoDB吧? 1. 从这个版本开始,可以支持 全文索引 了。 2. alter table可以不拷贝表了,且不阻塞写操作, online DDL ,酷炫吧。 画外音:并不是所有的alter table都这样。 3. 建表时,允许 一个table一个文件 了,具体能玩出什么花呢? 这样就能够实现,热数据表放SSD里,数据量大的表放HDD里了。 4. 可以支持 memcached插件 了,关系型数据库和memcached缓存实现在一起,支持几十万的吞吐量,是不是简化了系统架构? 5. 可以支持 只读实例 了,这样就能够实现: (1)把InnoDB表放在DVD或CD里,方便共享; (2)多个实例 共 用一份数据了; 这些有意思的特性,你会最想尝试哪一个呢? 画外音:我猜是memcached插件。 为帮助更多开发工程师、架构师掌握 MySQL 核心,这里推荐一下奈学最新打造的 《3天挑战架构师级MySQL海量数据设计与实践 》 在线专栏课。

Server automatically getting closed and facing 'ERR_STREAM_WRITE_AFTER_END' error along with data sending every time to client

帅比萌擦擦* 提交于 2021-02-10 18:36:58
问题 I am trying to get real-time data using Server-Sent Events from the Database Mysql and sending the value to the client Reactjs. Here is the code: server.js const mysql = require('mysql'); const app = require('express')() const fetch = require('node-fetch'); const con = mysql.createConnection({ host: 'localhost', user: 'root', password: 'root', database: 'databasetest', }); var increment = 0; app.get('/stream/:abc/:qwe', (request, response) => { console.log(`Request url: ${request.url}`); var

为什么是NewSQL?

不想你离开。 提交于 2021-02-10 18:35:42
想必看到此篇的同学对于newSQL已经不是很陌生了,那么直接进入今天的主题: mysql的问题在哪? 一、不能通过mysql的server把InnoDB变成一个分布式数据库。 因为mysql生成的执行计划是个单机的 二、一个分布式的plan执行起来很复杂且低效。 比如使用分布式方案Proxy,因为它不支持分布式的transaction,也不支持跨节点的join 三、异步或半同步复制 因为有时候数据出问题你不知道是否应该切换节点,因为异步的方式会导致一部分数据“还在路上”。尤其是对于多数据中心的复制和数据中心的容灾。 而NewSQL真正发展起来是在2014年末到2015年初的时候,Raft论文发表之后,真正的NewSQL理论基础就基本确立了。 那么从技术实现的角度分析,为什么这样的技术会诞生呢?它又能解决哪些过去的产品解决不了或者不是最优方案的场景呢? 首先,举一个范围查询的例子,如果要查找一个班级里成绩在80-90之间的学生,那么通过KV的API的要很麻烦的,但是SQL的优化器就很容易解决此类问题,写一句SQL就可以搞定。 其次是高可用,未来的系统肯定是要设计成Auto-Failover的,即自动恢复,需要人工去干预的容灾系统不是好厨子。 然后针对业务还要说几点: 比如按照ID去分库分表,比如使用一致性哈希去指导节点均衡。如果问题上升到了一定的复杂度

收藏!17 张程序员专属壁纸(使用频率很高)

落花浮王杯 提交于 2021-02-10 18:32:57
点击关注上方“ SQL数据库开发 ”, 设为“置顶或星标 ”,第一时间送达干货 1、三思后再写代码!!! 2、从世界上搜索喜欢你的人!!! 3、代码没写完,哪里有脸睡觉!!! 4、程序员的 Home 键!!! 5、编程是一门艺术!!! 6、云 ~~~~ 雨!!! 7、程序人生!!! 8、只有极客才懂!!! 9、黑客的世界!!! 10、黑~~~人!!! 11、 PHP 专属!!! 12、程序 ~ 代码!!! 13、我就是一个极客!!! 14、CODE!!! 15、源代码!!! 16、CODE PARTICLE!!! 17、一个While 引发的人生故事!!! 我是岳哥,最后给大家分享我写的SQL两件套: 《SQL基础知识第二版》 和 《SQL高级知识第二版》 的PDF电子版。里面有各个语法的解释、大量的实例讲解和批注等等,非常通俗易懂,方便大家跟着一起来实操。 有需要的读者可以下载学习,在下面的公众号「 数据前线 」( 非本号 )后台回复关键字: SQL ,就行 数据前线 ——End—— 后台回复关键字: 1024 ,获取一份精心整理的技术干货 后台回复关键字: 进群 ,带你进入高手如云的交流群。 推荐阅读 27岁发明SQL以后,上帝把他带走了 微信8.0不好玩?那可能是你打开方式不正确! 一个员工的离职成本有多恐怖! SQL养成这些好习惯是一笔财富