我想使用cl-dbi连接mysql.
在使用quicklisp在sbcl上安装cl-dbi之后,尝试连接到mysql,但失败并出现以下错误:
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
(user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
T
* (ql:quickload :cl-dbi)
To load "cl-dbi":
Load 2 ASDF systems:
alexandria closer-mop
Install 6 Quicklisp releases:
cl-annot cl-dbi cl-syntax named-readtables
split-sequence trivial-types
; Fetching #<URL "http://beta.quicklisp.org/archive/split-sequence/2012-07-03/split-sequence-1.1.tgz">
; 3.78KB
==================================================
3,872 bytes in 0.01 seconds (420.14KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-annot/2015-04-07/cl-annot-20150407-git.tgz">
; 9.80KB
==================================================
10,039 bytes in 0.00 seconds (9803.71KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/trivial-types/2012-04-07/trivial-types-20120407-git.tgz">
; 3.15KB
==================================================
3,228 bytes in 0.00 seconds (0.00KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/named-readtables/2015-03-02/named-readtables-20150302-git.tgz">
; 31.96KB
==================================================
32,732 bytes in 0.37 seconds (86.86KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-syntax/2015-04-07/cl-syntax-20150407-git.tgz">
; 3.03KB
==================================================
3,102 bytes in 0.00 seconds (3029.30KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-dbi/2015-04-07/cl-dbi-20150407-git.tgz">
; 11.13KB
==================================================
11,393 bytes in 0.71 seconds (15.76KB/sec)
; Loading "cl-dbi"
[package trivial-types]...........................
[package editor-hints.named-readtables]...........
[package editor-hints.named-readtables]...........
[package cl-syntax]...............................
[package cl-annot.util]...........................
[package cl-annot.core]...........................
[package cl-annot.expand].........................
[package cl-annot.syntax].........................
[package cl-annot.helper].........................
[package cl-annot]................................
[package cl-annot.std]............................
[package cl-annot.eval-when]......................
[package cl-annot.doc]............................
[package cl-annot.class]..........................
[package cl-annot.slot]...........................
[package split-sequence]..........................
[package closer-mop]..............................
[package closer-common-lisp]......................
[package closer-common-lisp-user].................
[package dbi.error]...............................
[package dbi.driver]..............................
[package dbi].
(:CL-DBI)
* (defvar *connection*
(dbi:connect :mysql
:database-name "dbname"
:username "username"
:password "pwd"))
To load "dbd-mysql":
Load 1 ASDF system:
dbd-mysql
; Loading "dbd-mysql"
To load "cl-mysql":
Load 1 ASDF system:
alexandria
Install 4 Quicklisp releases:
babel cffi cl-mysql trivial-features
; Fetching #<URL "http://beta.quicklisp.org/archive/trivial-features/2015-01-13/trivial-features-20150113-git.tgz">
; 10.22KB
==================================================
10,465 bytes in 0.00 seconds (10219.73KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/babel/2014-12-17/babel-20141217-git.tgz">
; 243.81KB
==================================================
249,666 bytes in 6.30 seconds (38.73KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/cffi/2014-11-06/cffi_0.14.0.tgz">
; 207.73KB
==================================================
212,717 bytes in 9.06 seconds (22.92KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/cl-mysql/2015-03-02/cl-mysql-20150302-git.tgz">
; 24.99KB
==================================================
25,594 bytes in 0.15 seconds (165.52KB/sec)
; Loading "cl-mysql"
[package babel-encodings].........................
[package babel]...................................
..................................................
[package cffi-sys]................................
[package cffi]....................................
..................................................
[package cffi-features]...........................
[package com.hackinghat.cl-mysql-system].....
debugger invoked on a LOAD-FOREIGN-LIBRARY-ERROR in thread
#<THREAD "main thread" RUNNING {B3E2369}>:
Unable to load foreign library (LIBMYSQLCLIENT).
Error opening shared object "libmysqlclient_r.so":
libmysqlclient_r.so: cannot open shared object file: No such file or directory.
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [RETRY ] Try loading the foreign library again.
1: [USE-VALUE ] Use another library instead.
2: [TRY-RECOMPILING ] Recompile system and try loading it again
3: [RETRY ] Retry
loading FASL for #<CL-SOURCE-FILE "cl-mysql" "system">.
4: [ACCEPT ] Continue, treating
loading FASL for #<CL-SOURCE-FILE "cl-mysql" "system">
as having been successful.
5: Retry ASDF operation.
6: [CLEAR-CONFIGURATION-AND-RETRY] Retry ASDF operation after resetting the
configuration.
7: [ABORT ] Give up on "cl-mysql"
8: Give up on "dbd-mysql"
9: Exit debugger, returning to top level.
(CFFI::FL-ERROR "Unable to load foreign library (~A).~% ~A" LIBMYSQLCLIENT "Error opening shared object \"libmysqlclient_r.so\":
libmysqlclient_r.so: cannot open shared object file: No such file or directory.")
环境信息:
操作系统:Debian 8.1
的mysql:5.5.43-0 deb8u1
sbcl:SBCL 1.2.4.debian
也无法使用cl-mysql clsql.
有人可以提供一些线索吗?
解决方法:
谷歌之后,从post和问题的建议是固定的.
> $sudo find / -name *libmysqlclient* /usr/share/doc/libmysqlclient18
> /usr/lib/i386-linux-gnu/libmysqlclient.so.18
> /usr/lib/i386-linux-gnu/libmysqlclient.so.18.0.0
> /usr/lib/i386-linux-gnu/libmysqlclient_r.so.18
> /usr/lib/i386-linux-gnu/libmysqlclient_r.so.18.0.0
> /var/cache/apt/archives/libmysqlclient18_5.5.42-1_i386.deb
> /var/cache/apt/archives/libmysqlclient18_5.5.43-0+deb8u1_i386.deb
> /var/lib/dpkg/info/libmysqlclient18:i386.postinst
> /var/lib/dpkg/info/libmysqlclient18:i386.postrm
> /var/lib/dpkg/info/libmysqlclient18:i386.list
> /var/lib/dpkg/info/libmysqlclient18:i386.shlibs
> /var/lib/dpkg/info/libmysqlclient18:i386.md5sums
只需创建libmysqlclient_r.so作为指向libmysqlclient.so.18的链接
$sudo ln /usr/lib/i386-linux-gnu/libmysqlclient.so.18 /usr/lib/i386-linux-gnu/libmysqlclient_r.so
之后,执行cl-dbi示例,它会成功运行.
* (ql:quickload :cl-dbi)
To load "cl-dbi":
Load 1 ASDF system:
cl-dbi
; Loading "cl-dbi"
(:CL-DBI)
* (defvar *connection*
(dbi:connect :mysql
:database-name "db-name"
:username "dbuser"
:password "dbpwd"))
To load "dbd-mysql":
Load 1 ASDF system:
dbd-mysql
; Loading "dbd-mysql"
...........
*CONNECTION*
* (setf query (dbi:prepare *connection*
"SHOW VARIABLES LIKE \"%version%\";"))
; in: SETF QUERY
; (SETF QUERY
; (DBI.DRIVER:PREPARE *CONNECTION*
; "SHOW VARIABLES LIKE \"%version%\";"))
; ==>
; (SETQ QUERY
; (DBI.DRIVER:PREPARE *CONNECTION*
; "SHOW VARIABLES LIKE \"%version%\";"))
;
; caught WARNING:
; undefined variable: QUERY
;
; compilation unit finished
; Undefined variable:
; QUERY
; caught 1 WARNING condition
#<DBD.MYSQL:<DBD-MYSQL-QUERY> {C3FF761}>
* (setf result (dbi:execute query))
; in: SETF RESULT
; (DBI.DRIVER:EXECUTE QUERY)
;
; caught WARNING:
; undefined variable: QUERY
; (SETF RESULT (DBI.DRIVER:EXECUTE QUERY))
; ==>
; (SETQ RESULT (DBI.DRIVER:EXECUTE QUERY))
;
; caught WARNING:
; undefined variable: RESULT
;
; compilation unit finished
; Undefined variables:
; QUERY RESULT
; caught 2 WARNING conditions
#<DBD.MYSQL:<DBD-MYSQL-QUERY> {C3FF761}>
* (loop for row = (dbi:fetch result)
while row
do (format t "~A~%" row))
; in: LOOP FOR
; (DBI.DRIVER:FETCH RESULT)
;
; caught WARNING:
; undefined variable: RESULT
;
; compilation unit finished
; Undefined variable:
; RESULT
; caught 1 WARNING condition
(Variable_name innodb_version Value 5.5.43)
(Variable_name protocol_version Value 10)
(Variable_name slave_type_conversions Value NIL)
(Variable_name version Value 5.5.43-0+deb8u1)
(Variable_name version_comment Value (Debian))
(Variable_name version_compile_machine Value i686)
(Variable_name version_compile_os Value debian-linux-gnu)
NIL
*