469,883 Members | 1,093 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,883 developers. It's quick & easy.

Access denied for user ''@'localhost'

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
Sep 26 '07 #1

✓ answered 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.  

19 139465
pbmods
5,821 Expert 4TB
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.
Sep 27 '07 #2
r035198x
13,262 8TB
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.
Sep 27 '07 #3
pbmods
5,821 Expert 4TB
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.  
Sep 27 '07 #4
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
Sep 27 '07 #5
pbmods
5,821 Expert 4TB
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.  
Sep 27 '07 #6
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.
Sep 28 '07 #7
pbmods
5,821 Expert 4TB
Heya, Markodilore.

To log into MySQL, use this:
Expand|Select|Wrap|Line Numbers
  1. /usr/local/mysql/bin/mysql -u root -p
  2.  
Sep 29 '07 #8
IT WORKED, IT WORKED, IT WORKED, THANK YOU VERY MUCH, MAN!!!!!!
Tell me where to send the money
Sep 29 '07 #9
pbmods
5,821 Expert 4TB
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 :)
Sep 29 '07 #10
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......
Jan 7 '08 #11
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....
Jan 7 '08 #12
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' );
Jun 6 '08 #13
pbmods
5,821 Expert 4TB
Heya, Strika.

You need to establish a connection to the MySQL database server (using mysql_connect()) before you can execute a query.
Jun 7 '08 #14
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".
Jun 7 '08 #15
pbmods
5,821 Expert 4TB
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.
Jun 9 '08 #16
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.
Jun 10 '08 #17
cl578
2
@pbmods
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!
Sep 26 '09 #18
tg3793
1
@pbmods
I would like to thank you SO MUCH for posting this information and caring so much about helping others with this. Now, over two years later I am able to make great use of this.

I am not a "spring chicken" when it comes to IT by any means. And I'd like to think that I am in the top one or two percent of people that I've ever known when it comes to tracking down the answer to IT related problems. Would you believe it took me about three hours of focussed effort to find that simple answer you gave here.

That's right; several dozen websites (including blogs and forums), doing searches through the html version of the MySQL users manual, and even a question that I posted to the #mysql IRC channel (which no one ever answered).


And for the future edification of anyone else that might come to this, I had to make a very slight modification to the answer that was given here because I am on a Windows XP machine. I installed vTiger which automatically installed MySQL within it's installation. So I typed the following:

C:\Program Files\vtigercrm-5.1.0\mysql\bin\mysql -u root -p

From there it prompted me for the root password and I was home free. ..Again, thank you thank you thank you.
Dec 11 '09 #19
guys, I had a same problem and I was searching for this solution, thank god, you guys saved my temper as well ... thanks it works
Oct 21 '10 #20

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Steve | last post: by
4 posts views Thread by Fabian von Romberg | last post: by
12 posts views Thread by Chad Crowder | last post: by
6 posts views Thread by ASP.Confused | last post: by
reply views Thread by ASP.Confused | last post: by
8 posts views Thread by Jeremy Ames | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.