1

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.

3
  • Can you run ldd /usr/local/lib/perl/5.10.1/auto/DBD/mysql/mysql.so and post the result in your question? Commented Mar 5, 2014 at 6:40
  • The result of ldd ...:linux-gate.so.1 => (0x001f9000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x008df000) /lib/ld-linux.so.2 (0x001cb000) Commented Mar 5, 2014 at 7:47
  • This cannot be right, auto/DBD/mysql/mysql.so depends much more libraries than what you listed. Commented Mar 5, 2014 at 8:18

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

7 Comments

On my system, linux mint 11 ldd /usr/local...command shows only linux-gate.so.1 => (0x00bc3000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00cb7000) /lib/ld-linux.so.2 (0x00b36000) and not libmysqlclient.so.18 not found. What do i do?? I had installed mysql using xampp.
@user3382201 I tested those on Fedora 19. What are the absolute paths of these libmysqlclient.so* files on your system?
After running find libmysqlclient.so*, it says no such file or directory
@user3382201 Try to install libmysqlclient-dev, if that package exists in your system; or search using your package manager for the package which includes 'libmysqlclient.so' and install it.
apt-get install libmysqlclient-dev says, unable to locate package... also my synaptic pkg mnger does not show any result for that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.