LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-09-2006, 06:01 PM   #1
jun_tuko
Member
 
Registered: Oct 2005
Location: Seattle, WA
Distribution: Fedora Core 4
Posts: 67

Rep: Reputation: 15
MYSQL: Access denied for user 'root'@'localhost' (using password: NO)


hello database gurus,
i have another one for you guys. i am getting this error:

[root@bluebananas mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

i don't know what's going on. i can get in, however, after providing a password, using command:

[root@bluebananas mysql]# mysql -u root -p mysql

but using commands:
1) mysql (plain)
2) mysqladmin variables

gave me the access error.

i have a webserver running using apache and php (works fine). i'm trying to integrate and use mysql to my system. i copied a php script from a book to test my php-apache-mysql connection but its not giving me any expected output.

you will notice that i placed "echo" before and after mysql_connect. it showed "connecting" on the browser, but seemed to hang because it does not show "after connecction".

here's the code:
///// database_connection.php
<?php
$dbUser = 'test_user';
$dbPass = 'test_pass';
$dbName = 'my_test';
$dbHost = 'localhost';

echo "Connecting";

$sql = mysql_connect($dbHost, $dbUser, $dbPass)
or die (mysql_error());

echo "After Connection";

mysql_select_db($dbName, $sql) or die (mysql_error());
?>

///// database_insert.php
<?php
include ('database_connection.php');

for ($i = 0; $i <= 50; $i++)
{
if($i % 2)
{
$data = $i.' -Odd Result';
}
else {
$data = $i.' -Even Result';
}

mysql_query("INSERT INTO my_table (my_value, my_date)
VALUES ('$data', now())") or die (mysql_error());
echo "Inserting: $data<br />";
}
echo "Done<br />";
?>

where does mysql put its errors by the way?

thanks guys!

jun
 
Old 01-09-2006, 06:16 PM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
Quote:
Originally Posted by jun_tuko
hello database gurus,
i have another one for you guys. i am getting this error:

[root@bluebananas mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

i don't know what's going on. i can get in, however, after providing a password, using command:

[root@bluebananas mysql]# mysql -u root -p mysql

but using commands:
1) mysql (plain)
2) mysqladmin variables

gave me the access error.
My guess, as I'm no guru yet, but did have the same problems you are having, is that the vanillya mysql command assumes the current user with no password. Now, this is fine if you don't care about security. My solution to this was to simply add to my ~/.bashrc file:
Code:
alias mysql="mysql -p"
Then the mysql command will use the current user, and prompt for a password.
Quote:
i have a webserver running using apache and php (works fine). i'm trying to integrate and use mysql to my system. i copied a php script from a book to test my php-apache-mysql connection but its not giving me any expected output.

you will notice that i placed "echo" before and after mysql_connect. it showed "connecting" on the browser, but seemed to hang because it does not show "after connecction".

here's the code:
///// database_connection.php
<?php
$dbUser = 'test_user';
$dbPass = 'test_pass';
$dbName = 'my_test';
$dbHost = 'localhost';

echo "Connecting";

$sql = mysql_connect($dbHost, $dbUser, $dbPass)
or die (mysql_error());

echo "After Connection";

mysql_select_db($dbName, $sql) or die (mysql_error());
?>
This is my connection script for your reference:

Code:
<?php # Script 6.4 - mysql_connect.php

define('DB_USER', '<username>');
define('DB_PASSWORD', '<password>');
define('DB_HOST', 'localhost');
define('DB_NAME', '<databasename>');

$dbc = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Could not connect to MySQL: ' . mysql_error());
mysql_select_db(DB_NAME);

Maybe, this will be a little more verbose, but the define statement may be a little more robust than just assigning a value? Maybe, a true guru can answer that one.

I don't know the answer to the last question, so hopefully someone else will come along with another answer.

Regards,

Alunduil

Last edited by alunduil; 01-09-2006 at 06:22 PM.
 
Old 02-16-2011, 12:20 PM   #3
britsfp
LQ Newbie
 
Registered: Feb 2011
Posts: 1

Rep: Reputation: 0
Thumbs up MYSQL: Access denied for user 'root'@'localhost' (using password: NO)

I have upgraded from Debian lenny to squeeze, and voila I got the same error on the first reboot and all the time since. After a lot of swearing and searching I tried this command :: mysql_setpermission.

That fixed it for good.

You can even set up some new users and their passwords too.

Regards
Frik Brits
 
Old 03-05-2013, 06:37 AM   #4
shijobaby
LQ Newbie
 
Registered: Jun 2011
Posts: 3

Rep: Reputation: Disabled
http://answerforu.com/2011/06/22/acc...ser-mysql-php/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sarge mysql-server Access denied for user: root@localhost infinity432 Linux - Software 2 05-18-2005 11:42 PM
MySQL: 'access denied for user' turbo_acura Linux - General 1 10-20-2004 08:34 AM
mySQL Access denied for user Gerardoj Linux - General 2 03-21-2004 10:13 AM
why I got "Access denied for user: 'root@localhost'" likedreamer Red Hat 1 11-09-2003 05:06 AM
MYSQL access denied for user c0c0deuz Linux - General 1 03-18-2003 02:44 PM


All times are GMT -5. The time now is 07:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration