Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

access denied for user " "@localhost MySql but can log in through access

Posted on 2011-09-13
4
Medium Priority
?
305 Views
Last Modified: 2012-05-12
Hers a really strange one that I simply cannot figure out.
Every time I or or web app trys to log into the MySql or any other database on our server we get the access denied for " " @localhost.
If I do not provide a database name when logging into MySql I can get in and when I do a show databases I only see
mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

Now here's the really weird part. I CAN get into any database from my PC using access (I downloaded the free mysql driver).
So why can't I log in at the console of the server? How can I fix this?
Help please!
0
Comment
Question by:edwarddoylesr
  • 2
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36529174
Here is my teaching example of how to do some of the basics in PHP and MySQL.  Copy it and install it on your server, substitute your own credentials at line 22-25 and see if it works for you.
<?php // RAY_mysql_example.php
error_reporting(E_ALL);


// THE ABSOLUTE MINIMUM YOU MUST UNDERSTAND TO USE PHP AND MYSQL
// MAN PAGE: http://php.net/manual/en/ref.mysql.php
// MAN PAGE: http://php.net/manual/en/mysql.installation.php
// MAN PAGE: http://php.net/manual/en/function.mysql-connect.php
// MAN PAGE: http://php.net/manual/en/function.mysql-select-db.php
// MAN PAGE: http://php.net/manual/en/function.mysql-real-escape-string.php
// MAN PAGE: http://php.net/manual/en/function.mysql-query.php
// MAN PAGE: http://php.net/manual/en/function.mysql-errno.php
// MAN PAGE: http://php.net/manual/en/function.mysql-error.php
// MAN PAGE: http://php.net/manual/en/function.mysql-num-rows.php
// MAN PAGE: http://php.net/manual/en/function.mysql-fetch-assoc.php
// MAN PAGE: http://php.net/manual/en/function.mysql-fetch-array.php
// MAN PAGE: http://php.net/manual/en/function.mysql-insert-id.php



// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";        // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";


// OPEN A CONNECTION TO THE DATA BASE SERVER
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))
{
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB CONNECTION: ";
    echo "<br/> $errmsg <br/>";
}

// SELECT THE MYSQL DATA BASE
if (!$db_sel = mysql_select_db($db_name, $db_connection))
{
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB SELECTION: ";
    echo "<br/> $errmsg <br/>";
    die('NO DATA BASE');
}
// IF THE SCRIPT GETS THIS FAR IT CAN DO QUERIES
echo "SUCCESS!";

Open in new window

0
 
LVL 18

Expert Comment

by:Garry Glendown
ID: 36529234
Did you allow for the user to connect from localhost? Please note there is a difference from the ACL point of view between 127.0.0.1 and localhost ...

For tests, do something like this as admin user:

   grant all privileges on DBNAME.* to 'USERNAME'@'localhost' identified by 'USERPASSWD';

after that, the usual "mysql_connect" call followed by the "mysql_select_db" ought to work fine ...
0
 

Accepted Solution

by:
edwarddoylesr earned 0 total points
ID: 36529844
It turned out to be a bad my.conf file.
I used my backup copy and I can now log in.

Thanks all,
0
 

Author Closing Comment

by:edwarddoylesr
ID: 36555797
The only difference I saw was the bind statement in the backup was not in the my.conf
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question