gpt4 book ai didi

mysql - cl-dbi 从 sbcl 查询 mysql 时出现错误 - 非法 :UTF-8 character starting at position 18

转载 作者:太空宇宙 更新时间:2023-11-03 19:00:34 26 4
gpt4 key购买 nike

今天尝试使用 cl-dbi 对 mysql 进行一些查询。但它因以下错误而失败:

debugger invoked on a BABEL-ENCODINGS:INVALID-UTF8-STARTER-BYTE in thread
#<THREAD "main thread" RUNNING {B3E2151}>: Illegal :UTF-8 character starting at position 18.

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name): 0: [ABORT] Exit debugger, returning to top level.

((LABELS BABEL-ENCODINGS::UTF-8-DECODER :IN "/home/angelo/quicklisp/dists/quicklisp/software/cffi_0.14.0/src/strings.lisp")
#<unavailable lambda list>)

这里是mysql字符集:

mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'collation%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)

更多测试在这里:
1. 我尝试根据 post 的建议将整个数据库转换为 utf-8 , 但它仍然失败并出现相同的错误。

  1. 8/3/2015:我在这里尝试查询当前 cl-dbi 连接中的字符集和排序规则。结果如下:
**Query:**
(setf query (dbi:prepare *connection*
"SHOW VARIABLES LIKE 'character_set%';"))
(setf result (dbi:execute query))
(loop for row = (dbi:fetch result)
while row
do (format t "~A~%" row))
**Result:**
(Variable_name character_set_client Value latin1)
(Variable_name character_set_connection Value latin1)
(Variable_name character_set_database Value utf8)
(Variable_name character_set_filesystem Value binary)
(Variable_name character_set_results Value latin1)
(Variable_name character_set_server Value latin1)
(Variable_name character_set_system Value utf8)
(Variable_name character_sets_dir Value /usr/share/mysql/charsets/)
NIL
**Query:**
(setf query (dbi:prepare *connection*
"SHOW VARIABLES LIKE 'collation%';"))
(setf result (dbi:execute query))
(loop for row = (dbi:fetch result)
while row
do (format t "~A~%" row))

**Result:**
(Variable_name collation_connection Value latin1_swedish_ci)
(Variable_name collation_database Value utf8_unicode_ci)
(Variable_name collation_server Value latin1_swedish_ci)
NIL

正如“Fernando Borretti”建议的那样,在发送“SET names 'utf8';”后,查询成功完成,问题已解决。以下是测试结果供引用:

**Sending:**
(setf query (dbi:prepare *connection* "SET names 'utf8';"))

(setf result (dbi:execute query))
(loop for row = (dbi:fetch result)
while row
do (format t "~A~%" row))
**Query:**
(setf query (dbi:prepare *connection*
"SHOW VARIABLES LIKE 'character_set%';"))
(setf result (dbi:execute query))
(loop for row = (dbi:fetch result)
while row
do (format t "~A~%" row))
**Result:**
(Variable_name character_set_client Value utf8)
(Variable_name character_set_connection Value utf8)
(Variable_name character_set_database Value utf8)
(Variable_name character_set_filesystem Value binary)
(Variable_name character_set_results Value utf8)
(Variable_name character_set_server Value latin1)
(Variable_name character_set_system Value utf8)
(Variable_name character_sets_dir Value /usr/share/mysql/charsets/)
NIL
**Query:**
(setf query (dbi:prepare *connection*
"SHOW VARIABLES LIKE 'collation%';"))
(setf result (dbi:execute query))
(loop for row = (dbi:fetch result)
while row
do (format t "~A~%" row))
**Result:**
(Variable_name collation_connection Value utf8_general_ci)
(Variable_name collation_database Value utf8_unicode_ci)
(Variable_name collation_server Value latin1_swedish_ci)
NIL

最佳答案

发送 SET NAMES utf8 有帮助吗?我从对 this 的回复中得到了灵感评论。

关于mysql - cl-dbi 从 sbcl 查询 mysql 时出现错误 - 非法 :UTF-8 character starting at position 18,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31745456/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com