Adam
Adam

Reputation: 731

Access denied for user 'root'

I downloaded an adobe flex mysql script (from a tutorial I am learning) and ran the script in my sql 5.5. It created a database, but it was stored in my wamp folder under:

C:\wamp\bin\mysql\mysql5.1.36\data

I have a test php page that is supposed to print out the data from the database (from the adobe tutorial).

But, when I load the test page from localhost/test.php it just says:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\wamp\www\test.php on line 7
Error connecting to MySQL

And if I run it from localhost:3306/test.php I get just gibberish:

B???
5.1.36-community-log????nKm`zell?ÿ÷??????????????Z\Ap3JZcfVZD???ÿ„Got packets out of order

What password do I use -- my wamp password / login name, or the new mysql5.5 root password? I've tried the mysql5.5 root & password, but I still can't connect.

Why is mysql5.5 loading the database under my older WAMP sql data folder? Is there some conflict having MySQL5.1 installed with WAMP, and MySQL5.5 I just installed separately?

Upvotes: 1

Views: 8220

Answers (4)

user2217741
user2217741

Reputation: 1

I spent almost the whole day resolving this issue so if this help anyone I solved it by using the following code:

// - Get Connection - //

$this->dbCon = mysqli_connect($this->dbHost,$this->dbUser) or 
    die("Connection failed:<br/>" . mysqli_connect_error());

// - Select Database - //

mysqli_select_db($this->dbCon,$this->dbName) or
    die("Selection failed: <br/>" .   mysqli_connect_error());

-and also by setting

  $cfg['Servers'][$i]['AllowNoPassword'] = true - in the config.inc.php file.

Hope that helps

Upvotes: 0

Cees Timmerman
Cees Timmerman

Reputation: 19644

After wasting most of a day on this problem, it turned out that all i had to do was supply the non-localhost hostname. I've no idea why (the user is allowed to connect from Any host), but it works!

root@base:~# mysql -u username -h hostname -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.

And in PHP:

Test 1807:
<?php
$username = "username";
$password = "password";
$hostname = "actualhostnamenotlocalhost"; 

$con = mysqli_connect($hostname, $username, $password);

// Check connection
if (mysqli_connect_errno($con)){
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_close($con);    

?>
OK.

Upvotes: 1

Kaley
Kaley

Reputation: 1

Same problem after updating my phpmyadmin version, and turn out was the config problem:

step 1)open the corresponding phpmyadmin installation directory , duplicate config.sample.inc.php to config.inc.php under the same directory .

step 2)Open config.inc.php

change

$cfg['Servers'][$i]['AllowNoPassword'] = **false**;

to

$cfg['Servers'][$i]['AllowNoPassword'] = **true**;

and save the file.

Upvotes: 0

Pete
Pete

Reputation: 635

Please verify if you are using the right password, with the help of phpMyAdmin or my sql work bench

if this is a fresh installation then you will not have any password for the root

You need to set the password and the start connecting to the database using the password that is set

also if you are able to run the script without specifying the password, that means, no password is set for the database

You can use the switch "use password" to NO and connect using root

Upvotes: 0

Related Questions