Access denied for user ''@'localhost' | Newbie | | Join Date: Sep 2007
Posts: 7
| |
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
| |
best answer - posted by pbmods |
Heya, Markodilore.
To log into MySQL, use this: -
/usr/local/mysql/bin/mysql -u root -p
-
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
| | | 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
| | | 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.
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
| | | re: Access denied for user ''@'localhost'
Heya, Markodilore.
Did you set up a root account for your MySQL database?
In the terminal type: -
> mysqladmin -u root password 'root password goes here'
-
And then to invoke the MySQL client: | | Newbie | | Join Date: Sep 2007
Posts: 7
| | | 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
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
| | | re: Access denied for user ''@'localhost'
Heya, Markodilore.
Looks like your MySQL installation has incorrect permissions.
Execute the following commands: -
> cd /usr/local/mysql
-
> sudo chown -R mysql data
-
> sudo chgrp -R mysql data
-
> sudo scripts/mysql_install_db --user=mysql
-
> sudo bin/mysqladmin -u root password 'password for root goes here'
-
| | Newbie | | Join Date: Sep 2007
Posts: 7
| | | 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: - Last login: Thu Sep 27 19:24:27 on console
-
Welcome to Darwin!
- Marko-Dilore-Computer:~ markodilore$ cd /usr/local/mysql
- Marko-Dilore-Computer:/usr/local/mysql markodilore$ sudo chown -R mysql data
-
Password:
- Marko-Dilore-Computer:/usr/local/mysql markodilore$ sudo chgrp -R mysql data
- Marko-Dilore-Computer:/usr/local/mysql markodilore$ sudo scripts/mysql_install_db --user=mysql
-
Password:
-
Installing all prepared tables
-
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
-
Fill help tables
-
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
-
-
To start mysqld at boot time you have to copy support-files/mysql.server
-
to the right place for your system
-
-
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
-
To do so, start the server, then issue the following commands:
-
./bin/mysqladmin -u root password 'new-password'
-
./bin/mysqladmin -u root -h Marko-Dilore-Computer.local password 'new-password'
-
See the manual for more instructions.
-
-
NOTE: If you are upgrading from a MySQL <= 3.22.10 you should run
-
the ./bin/mysql_fix_privilege_tables. Otherwise you will not be
-
able to use the new GRANT command!
-
-
You can start the MySQL daemon with:
-
cd . ; ./bin/mysqld_safe &
-
-
You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
-
cd sql-bench ; perl run-all-tests
-
-
Please report any problems with the ./bin/mysqlbug script!
-
-
The latest information about MySQL is available on the web at
-
http://www.mysql.com
-
Support MySQL by buying support/licenses at http://shop.mysql.com
- 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: - Marko-Dilore-Computer:/usr/local/mysql markodilore$ /usr/local/mysql/bin/mysql
-
Welcome to the MySQL monitor. Commands end with ; or \g.
-
Your MySQL connection id is 2
-
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'
How do you think i should access MySQL now? Again, thank you.
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
| | | re: Access denied for user ''@'localhost'
Heya, Markodilore.
To log into MySQL, use this: -
/usr/local/mysql/bin/mysql -u root -p
-
| | Newbie | | Join Date: Sep 2007
Posts: 7
| | | re: Access denied for user ''@'localhost'
IT WORKED, IT WORKED, IT WORKED, THANK YOU VERY MUCH, MAN!!!!!!
Tell me where to send the money
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
| | | 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
| | | 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: -
> cd /usr/local/mysql
-
> sudo chown -R mysql data
-
> sudo chgrp -R mysql data
-
> sudo scripts/mysql_install_db --user=mysql
-
> sudo bin/mysqladmin -u root password 'password for root goes here'
-
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
| | | 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
| | | 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): -
if( hasUserName( $safeUserName ) ){
-
appendToErrorMessage( "User name already exists in the database." );
-
return false;
-
} else {
-
$selectQuery = "INSERT INTO Users (
-
ID , UserName , UserPwd , LastLogin , LastTheme )
-
VALUES( NULL, '$safeUserName', '$safeUserPwd', '" . date( "Y-m-d H:i:s", time() ) . "', '" . DEFA_THEME . "' );";
-
-
echo $selectQuery . "<br />";
-
$dbReply = mysql_query( $selectQuery ) or die( "mysql_query error: " . mysql_error() );
-
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' ); |  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
| | | 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
| | | 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: - /**function getMySQLConnection()
-
Returns: resource $connection */
-
function getMySQLConnection()
-
/* throws ConnectionError, AND sets the error label. */{
-
if( $connection = mysql_connect( DB_SERVER, DB_NAME, DB_PASSWD ) )
-
{
-
return $connection;
-
} else {
-
appendToErrorMessage( "Could not open connection to users' database. Error: " . mysql_error() );
-
throw new ConnectionError( "Could not open connection to users' database. Error: " . mysql_error() );
-
}
-
} // getMySQLConnection
This is part of utils.php
In the register function, above the code posted upthread, I've got: -
$mySqlConnection = getMySQLConnection();
-
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".
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
| | | 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
| | | 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: - 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
| | | re: Access denied for user ''@'localhost' Quote:
Originally Posted by pbmods Heya, Markodilore.
To log into MySQL, use this: -
/usr/local/mysql/bin/mysql -u root -p
-
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!
|  | Similar MySQL Database bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,223 network members.
|