Installation

Remote MySQL database connection issues

Remote MySQL database connection issues

by Xiong Chiamiov -
Number of replies: 2
I am in the process of moving our webwork install off our primary server and onto a dedicated vm. The process has been mostly smooth, with the exception of the configuration of the database, which remains on the other machine.

As suggested in a previous thread, I have changed the $database_dsn string in global.conf to contain extra information about the host. Attempting to access any part of webwork that requires the database, however, gives me an error message:

error instantiating DB driver WeBWorK::DB::Driver::SQL for table set_user: DBI connect('database=webwork;host=oursite.com:3306','webworkWrite',...) failed: Can't connect to MySQL server on 'oursite.com' (13) at /opt/webwork/webwork2/lib/WeBWorK/DB/Driver/SQL.pm line 65
at /opt/webwork/webwork2/lib/WeBWorK.pm line 286

I can connect successfully to the database using the MySQL CLI, so I know it's accesible and I've gotten the proper permissions set.

I poked into SQL.pm to see what's happening at line 65, and tried replicating it in a Perl REPL, with success. Just to be extra-sure, I yank-putted it into a separate file, added the appropriate dsn/user/pass information, and ran it, also with success. Here are its contents:

use DBI;

$source = "dbi:mysql:database=webwork;host=oursite.com:3306";
$username = "webworkWrite";
$password = "asupersecretpassword";

$handle = DBI->connect_cached(
$source,
$username,
$password,
{
PrintError => 0,
RaiseError => 1,
},
);
die $DBI::errstr unless defined $handle;

I am a bit puzzled as to why this connects just fine while running practically the same code in webwork produces an error. Yes, I have triple-checked that the dsn, username and password all match between global.conf and this file.

Any ideas on why this isn't working? Alternatively, I'll take suggestions on how to tackle the problem - in Python, I'd probably drop into pdb in that subroutine and poke around a bit, but I'm not too familiar with Perl's development tools.
In reply to Xiong Chiamiov

Re: Remote MySQL database connection issues

by Michael Gage -
not sure what's going wrong. From the docs on DBI at

http://search.cpan.org/~capttofu/DBD-mysql-4.006/lib/DBD/mysql.pm#connect
I get:

use DBI;

 $dsn = "DBI:mysql:$database";
 $dsn = "DBI:mysql:database=$database;host=$hostname";
 $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";

 $dbh = DBI->connect($dsn, $user, $password);
what's different from your set up is the separate specification of the port.

;port=3306

Don't know if that would make a difference or not.

If you have access to the error log on the mysql database side of the request you might get some idea of why the the mysql connection fails
(or you might find that the request never gets anywhere near the mysqld daemon. ) That might help with the trouble shooting. The link above gives more details on using DBI.pm which might help as well.

Good luck. Let us know what solves this.

Take care,
Mike



In reply to Xiong Chiamiov

Re: Remote MySQL database connection issues

by Michael Gage -
We've had reports that this is another symptom of not having disabled selinux on the operating system you are setting up.

It's worth a try. There are instructions on disabling selinux at

http://webwork.maa.org/wiki/Installation_Manual_for_2.4_on_Fedora_11#Check_That_You_Have_Access_To_The_Internet_And_Continue_The_Installation

Hope this helps.

-- Mike