Connecting Tech Pros Worldwide Help | Site Map

Access denied for user ''@'localhost'

Newbie
 
Join Date: Sep 2007
Posts: 7
#1: Sep 26 '07
I have some experienced with MySQL on Windows, but now I'm trying with mac os, I can access the mysql from the terminal, but i can view the databases but i can't modify or create a new one. I get this message:
Expand|Select|Wrap|Line Numbers
  1. Welcome to the MySQL monitor.  Commands end with ; or \g.
  2. Your MySQL connection id is 4
  3. Server version: 5.0.37 MySQL Community Server (GPL)
  4.  
  5. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  6.  
  7. mysql> create database newland_tours;
  8. ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'newland_tours'
  9. mysql> 
Please somebody help me with this, I can pay you if you can through paypal,
Thank u
best answer - posted by pbmods
Heya, Markodilore.

To log into MySQL, use this:
Expand|Select|Wrap|Line Numbers
  1. /usr/local/mysql/bin/mysql -u root -p
  2.  
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Sep 27 '07

re: Access denied for user ''@'localhost'


Heya, Mark. Welcome to TSDN!

I went ahead and split your post into its own thread so as to avoid hijacking the original poster's thread.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#3: Sep 27 '07

re: Access denied for user ''@'localhost'


Quote:

Originally Posted by markodilore

I have some experienced with MySQL on Windows, but now I'm trying with mac os, I can access the mysql from the terminal, but i can view the databases but i can't modify or create a new one. I get this message:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.37 MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database newland_tours;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'newland_tours'
mysql>

Please somebody help me with this, I can pay you if you can through paypal,
Thank u

Your user account does not have create database priviledges.
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#4: Sep 27 '07

re: Access denied for user ''@'localhost'


Heya, Markodilore.

Did you set up a root account for your MySQL database?

In the terminal type:
Expand|Select|Wrap|Line Numbers
  1. > mysqladmin -u root password 'root password goes here'
  2.  
And then to invoke the MySQL client:
Expand|Select|Wrap|Line Numbers
  1. > mysql -u root -p
  2.  
Newbie
 
Join Date: Sep 2007
Posts: 7
#5: Sep 27 '07

re: Access denied for user ''@'localhost'


Thanks very much for answering me guys, but I don' now if i created an account. this is how i access the mysql screen troough the terminal, please tell me what i'm doing wrong:

Last login: Thu Sep 27 11:28:12 on console
Welcome to Darwin!
Marko-Dilore-Computer:~ markodilore$ sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
Password:
Starting MySQL database server
Marko-Dilore-Computer:~ markodilore$ cd /usr/local/mysql
Marko-Dilore-Computer:usr/local/mysql markodilore$ > mysqladmin -u root password '55555'
-bash: mysqladmin: Permission denied
Marko-Dilore-Computer:usr/local/mysql markodilore$ > mysqladmin -u root password 'orlando'
-bash: mysqladmin: Permission denied
Marko-Dilore-Computer:usr/local/mysql markodilore$ > mysqladmin -u root password ''
-bash: mysqladmin: Permission denied
Marko-Dilore-Computer:usr/local/mysql markodilore$ >

Where the first password('55555') is the one i tried to set up and the second one('orlando') is the one i used to install new programs on my mac, then i just tried to left it blank. I also tried to change the name root for 'user' and 'markodilore' but it didn't work either
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#6: Sep 27 '07

re: Access denied for user ''@'localhost'


Heya, Markodilore.

Looks like your MySQL installation has incorrect permissions.

Execute the following commands:
Expand|Select|Wrap|Line Numbers
  1. > cd /usr/local/mysql
  2. > sudo chown -R mysql data
  3. > sudo chgrp -R mysql data
  4. > sudo scripts/mysql_install_db --user=mysql
  5. > sudo bin/mysqladmin -u root password 'password for root goes here'
  6.  
Newbie
 
Join Date: Sep 2007
Posts: 7
#7: Sep 28 '07

re: Access denied for user ''@'localhost'


Thanks a lot, man, for helping me with this. Those commands you told me to insert seemed to work:
Expand|Select|Wrap|Line Numbers
  1. Last login: Thu Sep 27 19:24:27 on console
  2. Welcome to Darwin!
  3. Marko-Dilore-Computer:~ markodilore$ cd /usr/local/mysql
  4. Marko-Dilore-Computer:/usr/local/mysql markodilore$  sudo chown -R mysql data
  5. Password:
  6. Marko-Dilore-Computer:/usr/local/mysql markodilore$  sudo chgrp -R mysql data
  7. Marko-Dilore-Computer:/usr/local/mysql markodilore$  sudo scripts/mysql_install_db --user=mysql
  8. Password:
  9. Installing all prepared tables
  10. 070927 20:17:27 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql-5.0.37-osx10.3-powerpc/data/ is case insensitive
  11. Fill help tables
  12. 070927 20:17:27 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql-5.0.37-osx10.3-powerpc/data/ is case insensitive
  13.  
  14. To start mysqld at boot time you have to copy support-files/mysql.server
  15. to the right place for your system
  16.  
  17. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  18. To do so, start the server, then issue the following commands:
  19. ./bin/mysqladmin -u root password 'new-password'
  20. ./bin/mysqladmin -u root -h Marko-Dilore-Computer.local password 'new-password'
  21. See the manual for more instructions.
  22.  
  23. NOTE:  If you are upgrading from a MySQL <= 3.22.10 you should run
  24. the ./bin/mysql_fix_privilege_tables. Otherwise you will not be
  25. able to use the new GRANT command!
  26.  
  27. You can start the MySQL daemon with:
  28. cd . ; ./bin/mysqld_safe &
  29.  
  30. You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
  31. cd sql-bench ; perl run-all-tests
  32.  
  33. Please report any problems with the ./bin/mysqlbug script!
  34.  
  35. The latest information about MySQL is available on the web at
  36. http://www.mysql.com
  37. Support MySQL by buying support/licenses at http://shop.mysql.com
  38. Marko-Dilore-Computer:/usr/local/mysql markodilore$  sudo bin/mysqladmin -u root password '55555'
But I think now that i have made theese changes I should log on in a different way, because I keep getting this message:
Expand|Select|Wrap|Line Numbers
  1. Marko-Dilore-Computer:/usr/local/mysql markodilore$ /usr/local/mysql/bin/mysql
  2. Welcome to the MySQL monitor.  Commands end with ; or \g.
  3. Your MySQL connection id is 2
  4. Server version: 5.0.37 MySQL Community Server (GPL)
  5.  
  6. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  7.  
  8. mysql> create database newland_tours;
  9. ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'newland_tours'
How do you think i should access MySQL now? Again, thank you.
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#8: Sep 29 '07

re: Access denied for user ''@'localhost'


Heya, Markodilore.

To log into MySQL, use this:
Expand|Select|Wrap|Line Numbers
  1. /usr/local/mysql/bin/mysql -u root -p
  2.  
Newbie
 
Join Date: Sep 2007
Posts: 7
#9: Sep 29 '07

re: Access denied for user ''@'localhost'


IT WORKED, IT WORKED, IT WORKED, THANK YOU VERY MUCH, MAN!!!!!!
Tell me where to send the money
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#10: Sep 29 '07

re: Access denied for user ''@'localhost'


Heya, Markodilore.

You're most welcome. Take the money and go have a good time in my honor.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Newbie
 
Join Date: Jan 2008
Posts: 2
#11: Jan 7 '08

re: Access denied for user ''@'localhost'


Quote:

Originally Posted by pbmods

Heya, Markodilore.

Looks like your MySQL installation has incorrect permissions.

Execute the following commands:

Expand|Select|Wrap|Line Numbers
  1. > cd /usr/local/mysql
  2. > sudo chown -R mysql data
  3. > sudo chgrp -R mysql data
  4. > sudo scripts/mysql_install_db --user=mysql
  5. > sudo bin/mysqladmin -u root password 'password for root goes here'
  6.  

My situation is similar. But I can only login as an anonymous user -- '@'localhost.
There are 2 dbs only.

I execute the command above and I stuck at sudo bin/mysqladmin -u root password 'password for root goes here'

my command: sudo ./bin/mysqladmin -u root password '' (no password)
but it complains 'Access denied; you need the SUPER privilege for this operation'. What? I think I got all permission of mac tiger......
Newbie
 
Join Date: Jan 2008
Posts: 2
#12: Jan 7 '08

re: Access denied for user ''@'localhost'


Quote:

Originally Posted by kenpeter

My situation is similar. But I can only login as an anonymous user -- '@'localhost.
There are 2 dbs only.

I execute the command above and I stuck at sudo bin/mysqladmin -u root password 'password for root goes here'

my command: sudo ./bin/mysqladmin -u root password '' (no password)
but it complains 'Access denied; you need the SUPER privilege for this operation'. What? I think I got all permission of mac tiger......

mysql version - 5.0.45..... I think that is why super privilege won't work....
Newbie
 
Join Date: May 2007
Posts: 19
#13: Jun 6 '08

re: Access denied for user ''@'localhost'


I've got a problem in the same vein, but since nothing I've tried works, I strongly suspect myself of a PEBKAC error :)

The scenario is this: a form for logging in, which does a SELECT and an UPDATE, and a form for registering, which should do an INSERT. The login form works flawlessly, the register form fails with the following output:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'emacovei'@'localhost' (using password: NO) in /home/studs/2004/emacovei/html/php/register.php on line 39

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/studs/2004/emacovei/html/php/register.php on line 39
mysql_query error: Access denied for user 'emacovei'@'localhost' (using password: NO)

Guilty code (the last line causes the problems, as shown by the "or die" output above):
Expand|Select|Wrap|Line Numbers
  1.         if( hasUserName( $safeUserName ) ){
  2.             appendToErrorMessage( "User name already exists in the database." );
  3.             return false;
  4.         } else {
  5.             $selectQuery = "INSERT INTO Users (
  6.         ID , UserName , UserPwd , LastLogin , LastTheme )
  7. VALUES( NULL, '$safeUserName', '$safeUserPwd', '" . date( "Y-m-d H:i:s", time() ) . "', '" . DEFA_THEME . "' );";
  8.  
  9. echo $selectQuery . "<br />";
  10.             $dbReply = mysql_query( $selectQuery ) or die( "mysql_query error: " . mysql_error() );
  11.  
I've checked my priorities when writing the code for the login form, and I'm OK in that department. This is why I'm leaning towards this being just a stupid error.

A $selectQuery example would be:
INSERT INTO Users ( ID , UserName , UserPwd , LastLogin , LastTheme ) VALUES( NULL, 'aaa', 'aaa', '2008-06-06 22:53:06', 'ThemeTriTri.css' );
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#14: Jun 7 '08

re: Access denied for user ''@'localhost'


Heya, Strika.

You need to establish a connection to the MySQL database server (using mysql_connect()) before you can execute a query.
Newbie
 
Join Date: May 2007
Posts: 19
#15: Jun 7 '08

re: Access denied for user ''@'localhost'


Quote:

Originally Posted by pbmods

Heya, Strika.

You need to establish a connection to the MySQL database server (using mysql_connect()) before you can execute a query.

Heya, pbmods.

The database connection is established via a wrapper function to mysql_connect, the same one I'm calling from the login form. Plus, opening the database doesn't die on me; essentially, it's all going great until I call mysql_query().

I didn't include the full connection code, because, as stated, it was verified via the login action (and via an independent script, and via the "or die"s). Based on that, I'll take a leap of faith and say it's correct, but anyhow, here it is:

Expand|Select|Wrap|Line Numbers
  1. /**function getMySQLConnection()
  2. Returns: resource $connection */
  3. function getMySQLConnection()
  4. /* throws ConnectionError, AND sets the error label. */{
  5.     if( $connection = mysql_connect( DB_SERVER, DB_NAME, DB_PASSWD ) )
  6.     {
  7.         return $connection;
  8.     } else {
  9.         appendToErrorMessage( "Could not open connection to users' database. Error: " . mysql_error() );
  10.         throw new ConnectionError( "Could not open connection to users' database. Error: " . mysql_error() );
  11.     }
  12. } // getMySQLConnection
This is part of utils.php
In the register function, above the code posted upthread, I've got:


Expand|Select|Wrap|Line Numbers
  1. $mySqlConnection = getMySQLConnection();
  2. mysql_select_db( DB_DATABASE, $mySqlConnection ) or die( "Database Selection Error: " . mysql_error() );
getMySQLConnection() doesn't throw exceptions, and mysql_select_db doesn't die. Based on that, I'm looking for the error in the "else".
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#16: Jun 9 '08

re: Access denied for user ''@'localhost'


Can you verify that the connection code is being run?

The reason I ask is that PHP is reporting the 'access denied' error is being triggered by mysql_query(), not mysql_connect(), which would lead me to believe that at the time your script attempts to call mysql_query(), the connection has not been established.

PHP will attempt to establish a connection using the default values specified in php.ini, which is usually maybe a Username, and that's it. I'm thinking that's what happened based on the "using password NO" part.
Newbie
 
Join Date: May 2007
Posts: 19
#17: Jun 10 '08

re: Access denied for user ''@'localhost'


You might laugh at this.

I took up pbmods' advice, and tried to mess around the connection code. Around it, not with it. I've:

* put echoes in getMySQLConnection, one right before returning the connection, the other before throwing the exception.
* commented out:
$mySqlConnection = getMySQLConnection(); and put
$mySqlConnection = mysql_connect( "...", "...", "..." ) or die( "Connection Error: " . mysql_error());
with the params hardcoded.
* went in Notepad++ and search-highlighted every occurrence of $mySqlConnection - just in case I have a typo.
* copy/pasted the SELECT from login.php, hardcoded the username and tried to print on page.
U-oh! Same error as from the INSERT. So I look between mysql_select_db and selectQuery. The only notable thing there was:

Expand|Select|Wrap|Line Numbers
  1.  if( hasUserName( $safeUserName ) ){
Thing was, the script was pretty much having its cake and eating it, too. All connection, db open, etc. code was correct.

But hasUserName:
- connects to the db,
- executes "SELECT UserName FROM Users WHERE UserName = '" . $safeUserName . "';",
- CLOSES THE CONNECTION
- and returns true or false.

After calling it, there's no more connection.

I moved the connecting on the "else" branch, and that's it.
Newbie
 
Join Date: Sep 2009
Posts: 2
#18: Sep 26 '09

re: Access denied for user ''@'localhost'


Quote:

Originally Posted by pbmods View Post

Heya, Markodilore.

To log into MySQL, use this:

Expand|Select|Wrap|Line Numbers
  1. /usr/local/mysql/bin/mysql -u root -p
  2.  

I know that the initial post is from 2 years ago, but I would like to say Thank You so much for answering this question. This answer really helped me and as a result, I am now a member of the website, which is not something I normally do...

Thank You, again!
Reply