powerhouse has asked for the wisdom of the Perl Monks concerning the following question:

I did a search in here and found a answer, but could not get it to work. Can you please offer me some advice to help me solve this problem?

Software error: DBI connect('database=DB_Name;host=I_Had_IP_Here','USER_HERE','USER_PW +_HERE') failed: Access denied for user: 'USER_HERE@cpanel3165.hmp.com +' (Using password: YES) at test.cgi line 7

I did not put the @cpanel3165.hmp.com in the username, why is it adding it?
It even adds it if I put @myrealdomain.com!
I don't understand why it's adding it.

Here is my code, can you see the problem that is making it not be able to connect? I changed the REAL info of course, but You should get the idea:
#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard :cgi-lib); use DBI; use strict; my $dbh = DBI->connect("DBI:mysql:database=DATABASE_NAME;host=10.10.10 +.10", "USER_HERE", "USER_HERE_PW", {'RaiseError' => 1}) or die $DBI->errstr; my $sth = $dbh->prepare (qq{ SELECT some_cell FROM `table_name` }) +; $sth->execute(); my $_content; while($_cell_whatever = $sth->selectrow_array()) { $_content .= $_cell_whatever . br() . "\n"; } $sth->finish(); print header(), start_html(), $_content, end_html();
That gets the error at the top of this page. I've tried lots of different things. On the HOST I'm trying to access, I even added the main server name(hmp.com) as a host allowed to access the database. I added a new user and granted it permission to access that database and so forth.

Any thing you see that I really need to modify?

Thank you much for ANYTHING you can share.

thx,
Richard

Replies are listed 'Best First'.
Re: Remote Database Connection... in MySQL
by tachyon (Chancellor) on Oct 22, 2003 at 10:23 UTC

    MySQL looks at usernames not as 'username' but as 'username@ip_addresss'. Off the command line this generally ends up as 'username@localhost' which is the default allow when you do a grant. In the mysql database user table the Host field can be amongst other things 'localhost' - allow local conns for that user or '%' which as expected allows connections from an ip that matches '%' ie all. Quickfix:

    DBI->connect("DBI:mysql:database=DATABASE_NAME", "USER_HERE@localhost", "USER_HERE_PW", If you actually mean really remote access you need this syntax: $port = 3306; $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dbh = DBI->connect($dsn, $user, $password); # more details on this (you could update the Host field from 'localhos +t' # to '%' and FLUSH PRIVILEGES to get it to take effect. mysql> use mysql Database changed mysql> show tables; +-----------------+ | Tables_in_mysql | +-----------------+ | columns_priv | | db | | func | | host | | tables_priv | | user | +-----------------+ 6 rows in set (0.00 sec) mysql> select * from user\G *************************** 1. row *************************** Host: localhost User: root Password: bipitybopityboo Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y [snip] max_questions: 0 max_updates: 0 max_connections: 0 *************************** 2. row *************************** Host: % User: remote_god Password: TheCanBeOnlyOne Select_priv: HeavenOrHell Insert_priv: Adam&Eve Update_priv: Birth Delete_priv: Death [snip] max_questions: Eternal max_updates: Last try failed max_connections: ?

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Remote Database Connection... in MySQL
by edan (Curate) on Oct 22, 2003 at 07:08 UTC