在utf8_general_ci和之间utf8_unicode_ci,性能方面有什么不同吗?
尝试通过MySQL中的存储过程进行选择时,我得到以下错误.
操作'='的非法混合排序(latin1_general_cs,IMPLICIT)和(latin1_general_ci,IMPLICIT)
关于这里可能出现什么问题的任何想法?
表的排序规则latin1_general_ci与where子句中的列的排序规则相同latin1_general_cs.
我在处理大量数据时遇到这个奇怪的错误......
Error Number: 1267
Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
SELECT COUNT(*) as num from keywords WHERE campaignId='12' AND LCASE(keyword)='hello again 昔 ã‹ã‚‰ ã‚ã‚‹ å ´æ‰€'
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能解决这个问题?我可以以某种方式逃避字符串,因此不会发生此错误,或者我是否需要以某种方式更改我的表格编码,如果是这样,我应该将其更改为什么?
刚刚从上一个问题得到了这个答案,它有效!
SELECT username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount
FROM ratings WHERE month='Aug' GROUP BY username HAVING TheCount > 4
ORDER BY TheAverage DESC, TheCount DESC
Run Code Online (Sandbox Code Playgroud)
但当我坚持这个额外的位时,会出现这个错误:
文档#1267 - 操作'='的非法混合排序(latin1_swedish_ci,IMPLICIT)和(latin1_general_ci,IMPLICIT)
SELECT username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount FROM
ratings WHERE month='Aug'
**AND username IN (SELECT username FROM users WHERE gender =1)**
GROUP BY username HAVING TheCount > 4 ORDER BY TheAverage DESC, TheCount DESC
Run Code Online (Sandbox Code Playgroud)
该表是:
id, username, rating, month
我正在尝试设置一些简单的SQL脚本来帮助进行一些短期数据库管理.因此,我正在设置变量,以便更容易重用这些脚本.
我遇到的问题特别是LIKE子句.
SET @email = 'test@test.com';
SELECT email from `user` WHERE email LIKE '%@email%';
Run Code Online (Sandbox Code Playgroud)
所以我想让它根据变量中的电子邮件SET找到结果.如果我手动将电子邮件输入LIKE子句,则查询有效.
如何让LIKE子句与用户变量一起使用?
更新:@dems的答案适用于这个简单的情况,但我遇到了更复杂的查询问题.
SET @email = 'test@test.com';
SELECT project.projectno, project.projectname, login.username,
CONCAT(login.firstname, ' ', login.lastname), projectuser.title
FROM projectuser
INNER JOIN login ON projectuser.uid = login.uid
LEFT JOIN project ON projectuser.pid = project.pid
WHERE login.username LIKE CONCAT ('%', @email, '%')
Run Code Online (Sandbox Code Playgroud)
给我错误"功能mydb.CONCAT不存在"
查询在没有CONCAT()的情况下工作:
SET @email = 'test@test.com';
SELECT project.projectno, project.projectname, login.username,
CONCAT(login.firstname, ' ', login.lastname), projectuser.title
FROM projectuser
INNER JOIN login ON projectuser.uid = login.uid
LEFT JOIN project …Run Code Online (Sandbox Code Playgroud) 我检查了数据库表,发现它是latin1_swedish_ci那么我已经改变了它utf8_general_ci,然后我改变了从整理latin1_swedish_ci到utf8_general_ci所有领域.
它仍然给我同样的错误.
操作'='的非法混合排序(utf8_general_ci,IMPLICIT)和(utf8_unicode_ci,IMPLICIT)
谢谢,
我需要你的帮助来确定为什么会出现这个错误
Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
Run Code Online (Sandbox Code Playgroud)
该程序工作正常,直到昨天,今天它开始给出非法混合排序错误.我检查了我的数据库的每个表,所有的表及其列都在一个字符集和排序规则中: - utf8 utf8_unicode_ci.
我创建了另一个具有相同structrue的模式,并尝试执行相同的查询它工作正常,但不是在其原始模式.
任何人都可以提供任何意见吗?为什么会这样?
好吧,我放弃了.我有2天这个错误,我需要帮助.
免责声明:我需要帮助改进这个问题,并会尽力描述手头的问题,到目前为止我已经做了什么来解决这个问题,并分享博客文章和我读过的文件解.
问题(也在下文中提到):
所以问题是,为什么从Rails运行而不是从mysql命令行运行时,相同的查询表现不同?具体来说,"(utf8_general_ci,COERCIBLE)"来自哪里?
问题:Autoresponder.find_by(keyword: '')失败并出现以下错误:
ActiveRecord::StatementInvalid: Mysql2::Error: Illegal mix of collations
(utf8mb4_unicode_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE)
for operation '=':
SELECT `autoresponders`.*
FROM `autoresponders`
WHERE `autoresponders`.`keyword` = ''
LIMIT 1
Run Code Online (Sandbox Code Playgroud)
Autoresponder 是具有该属性的模型 keyword
我读到我需要指定我的校对.所以我测试了以下代码:
Autoresponder.where('keyword collate utf8mb4_unicode_ci = ?', '')
Run Code Online (Sandbox Code Playgroud)
并得到以下错误:
Illegal mix of collations
(utf8mb4_unicode_ci,EXPLICIT) and (utf8_general_ci,COERCIBLE)
for operation '=':
SELECT `autoresponders`.*
FROM `autoresponders`
WHERE (keyword collate utf8mb4_unicode_ci = '')
Run Code Online (Sandbox Code Playgroud)
所做的一切都是将整理从IMPLICIT改为EXPLICIT.
我尝试在Sequel Pro中运行查询并且它有效(使用和不使用collate关键字).为清楚起见,这里是查询:
SELECT `autoresponders`.*
FROM `autoresponders`
WHERE (keyword collate utf8mb4_unicode_ci = '');
SELECT `autoresponders`.*
FROM `autoresponders`
WHERE (keyword …Run Code Online (Sandbox Code Playgroud) 尝试通过 MySQL 中的存储过程进行选择时出现以下错误
操作“=”的排序规则 (utf8mb4_unicode_ci,IMPLICIT) 和 (utf8mb4_general_ci,IMPLICIT) 的非法混合。
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' or Variable_name LIKE 'collation%';
'character_set_client', 'utf8'
'character_set_connection', 'utf8'
'character_set_database', 'utf8mb4'
'character_set_filesystem', 'binary'
'character_set_results', 'utf8'
'character_set_server', 'utf8mb4'
'character_set_system', 'utf8'
'collation_connection', 'utf8_general_ci'
'collation_database', 'utf8mb4_unicode_ci'
'collation_server', 'utf8mb4_unicode_ci'
Run Code Online (Sandbox Code Playgroud)
所有表都在 utf8mb4_unicode_ci 中,字符集为 utf8mb4。
存储过程代码:
CREATE DEFINER=`dev_user`@`%` PROCEDURE `UPLOAD_ROSTER_FOR_DISTRICT`(IN JOBID INT, IN CHUNKID INT, IN DISTRICTID INT, IN DISTRICTYEARID INT)
BEGIN
DECLARE STUDENTSADDED INT DEFAULT 0;
DECLARE CLASSESADDED INT DEFAULT 0;
DECLARE TEACHERSADDED INT DEFAULT 0;
DECLARE STUDENTSEDITED INT DEFAULT 0;
DECLARE …Run Code Online (Sandbox Code Playgroud) 这个问题与两种不同类型的编码之间的PHP字符串比较并不重复,因为我的问题需要SQL解决方案,而不是PHP解决方案.
背景 ►有一个博物馆有两个数据库,engine=INNODB charset=utf8 collate=utf8_unicode_ci两个不同的PHP系统使用相同的字符集和校对().每个PHP系统以不同的方式存储相同的数据,下一个图像是一个例子:
这种方式已经存储了大量数据,两个系统都运行正常,因此我无法更改PHP编码或数据库.一个系统处理来自票房的销售,另一个系统处理来自网站的销售.
问题 ►我需要将右列(tipo_boleto_tipo)与左列()进行比较tipo,以便在左表的另一列中获取值(在图像中看不见),但由于存储了相同的值,因此我没有得到任何结果不同的,例如,当我搜索"Niños"时,找不到它,因为它被存储为"Niños"(西班牙语中的"儿童").我尝试通过使用PHP来实现它utf8_encode,utf8_decode但是速度慢得令人无法接受,所以我认为最好只使用SQL.这些数据将用于统一的销售报告(票房和互联网),并且必须比较数十万行,这就是为什么它在PHP上的速度如此之慢.
问题 ►有像什么utf8_encode或utf8_decode在MYSQL,让我来匹配相当于两列的值?任何其他建议将是受欢迎的.
接下来是我当前的代码(没有结果):
DATABASE TABLE COLUMN
? ? ?
SELECT boleteria.tipos_boletos.genero ? DESIRED COLUMN.
FROM boleteria.tipos_boletos ? DATABASE WITH WEIRD CHARS.
INNER JOIN venta_en_linea.ventas_detalle ? DATABASE WITH PROPER CHARS.
ON venta_en_linea.ventas_detalle.tipo_boleto_tipo = boleteria.tipos_boletos.tipo
WHERE venta_en_linea.ventas_detalle.evento_id='1'
AND venta_en_linea.ventas_detalle.tipo_boleto_tipo = 'Niños'
Run Code Online (Sandbox Code Playgroud)
这条线ON venta_en_linea.ventas_detalle.tipo_boleto_tipo = boleteria.tipos_boletos.tipo永远不会起作用,因为两个值都不同("Niños"vs"Niños").