My company has a Perl application in server with IP : 10.10.3.39
And because of the new rule implemented, I must migrate the database to MySQL DB in server with IP : 10.10.1.18
My company DB administrator has create an account and grant the access for the apps with username : 'user'@'10.10.3.39'
. So the account just can be used from server with IP 10.10.3.39
I tried the connection in the server using command mysql -h 10.10.1.18 -u user -p
[hanief@dev39 project]$ mysql -h 10.10.1.18 -u user -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 19484169
Server version: 10.0.15-MariaDB mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
I have a database connection script test_db.pm
in Perl like this:
use DBI;
$user = "user";
$pw = 'password';
$dbh = DBI->connect("DBI:mysql:database=mysql;host=10.10.1.18;mysql_enable_utf8=1",$user, $pw, %attr) or die "Cannot connect to MySQL server\n";
And then, I tried to run it using command perl test_db.pm
, I got this error
[hanief@dev39 project]$ perl test_db.pm
DBI connect('database=mysql;host=10.10.1.18;port=3306;mysql_enable_utf8=1','user',...)
failed: Access denied for user 'user'@'%' to database 'mysql' at test_db.pm line 6.
Cannot connect to MySQL server
I don't know why the account name suddenly has @'%'
behind it
I have tried to change the variable $user
to :
$user = "user\@10.10.3.39";
failed: Access denied for user '[email protected]'@'10.10.3.39' (using password: YES) at test_db.pm line 6.
$user = "user\@'10.10.3.39'";
failed: Access denied for user 'user@'10.10.3.39''@'10.10.3.39' (using password: YES) at test_db.pm line 6.
$user = "'user'\@'10.10.3.39'";
failed: Access denied for user 'user'@'10.10.3.39'@'10.10.3.39' (using password: YES) at test_db.pm line 6.
But still, didn't work. The server still can't connected to DB server.
I Don't know why there's an extra
@'10.10.3.39'
behind the user account. And don't know why%
before, suddenly changed to10.10.3.39
Any solution for my case?
DBI_TRACE
environment variable to a non-zero value may help. UsingDBI_TRACE=9
gives approximately the most information available. – EustasiusDBI_TRACE
set and capture the output (it is written to standard error, so you might needperl yourscript.pl >output.1 2>&1
(assuming a Bourne/POSIX style shell). Then run the connection to the new server withDBI_TRACE
set and capture that output. Now compare the two sets of outputs to see what is different. There should be something that's different. But I know not what. (Disclaimer: I'm not a MySQL user — but I did write most of theDBD::Informix
driver, and I still maintain it, albeit not very actively). – Eustasius