简体   繁体   中英

perl: symbol lookup error: /usr/local/lib/perl/5.10.1/auto/DBD/mysql/mysql.so: undefined symbol: mysql_init

I am trying to connect perl and mysql in a program but receive error: perl: symbol lookup error: /usr/local/lib/perl/5.10.1/auto/DBD/mysql/mysql.so: undefined symbol: mysql_init. Please guide..

I have installed mysql through xampp and run it using xampp (/opt... commands) on terminal. Mysql is running successfully from terminal, but i cannot retreive values through perl program.

Perl program i am running is:

#!/usr/bin/perl -w
use DBI;
$dbh = DBI->connect('dbi:mysql:first','root','shaifu')
or die "Connection Error: $DBI::errstr\n";
$sql = "select * from q";
$sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
while (@row = $sth->fetchrow_array) {
print "@row\n";
} 

where first is database and q is table.

Also DBI and DBD are installed as perl -e 'use DBI' and perl -e 'use DBD::mysql;' return nothing on terminal.

Please help me to solve the problem.

Okay, I will cut off this inefficient information query process, and just guess what the problem is.

/usr/local/lib/perl/5.10.1/auto/DBD/mysql/mysql.so: undefined symbol: mysql_init

This means one of the libraries depended by auto/DBD/mysql/mysql.so cannot find, so

ldd /usr/local/lib/perl/5.10.1/auto/DBD/mysql/mysql.so

will show something like

...
libmysqlclient.so.18 => not found

And this means loader cannot find libmysqlclient.so.18 . This could means

  1. you does not have this library, this could be fixed, for example in Fedora, by yum install community-mysql-libs ;
  2. you have it, but it does not in the search paths of loader, this could be fixed, for example in bash, export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/path/to/libmysqlclient , suppose your libmysqlclient.so is located under /path/to/libmysqlclient .
  3. you also could run /sbin/ldconfig -n /path/to/libmysqlclient as root to add /path/to/libmysqlclient , which is the directory that includes your libmysqlclient.so* , to the library search paths of your system.

By the way, if it is possible, you should always install any software you need through the package manager of your Linux distribution, this could avoid almost all of these annoying dependency problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM