This question already has answers here:
MySQL ERROR 1045 (28000): Access denied for user 'bill'#'localhost' (using password: YES)
(43 answers)
Closed 3 years ago.
I wrote some function used by a php webpage, in order to interact with a mysql database. When I test them on my server I get this error:
"Connect failed: Access denied for user 'root'#'localhost' (using password: YES)"
I am able to use them on my pc (using XAMPP) and I can navigate through the tables of the database using the command line in the server. However, the webpage fails to connect. I've checked the password but with no results. It's correct (otherwise I could not log in to mysql from the command line).
The call of the function is the following:
$conn = new mysqli("localhost", "root", "password", "shop");
Do I have to set something in my server? Thanks
Edit:
PHP version 5.3.3-7+squeeze1
mysql version: 5.1.49-3
both on debian
I solved in this way:
I logged in with root username
mysql -u root -p -h localhost
I created a new user with
CREATE USER 'francesco'#'localhost' IDENTIFIED BY 'some_pass';
then I created the database
CREATE DATABASE shop;
I granted privileges for new user for this database
GRANT ALL PRIVILEGES ON shop.* TO 'francesco'#'localhost';
Then I logged out root and logged in new user
quit;
mysql -u francesco -p -h localhost
I rebuilt my database using a script
source shop.sql;
And that's it.. Now from php works without problems with the call
$conn = new mysqli("localhost", "francesco", "some_pass", "shop");
Thanks to all for your time :)
Is there a user account entry in the DB for root#localhost? In MySQL you can set different user account permissions by host. There could be several different accounts with the same name combined with the host they are connecting from. The most common are root#127.0.0.1 and root#localhost. These can have different passwords and permissions. Make sure root#localhost exist and has the settings you expect.
I am willing to bet, based on your explanation, that this is the problem. Connecting from another PC uses a different account than root#localhost and the command line I think connects using root#127.0.0.1.
From what you've said so far, it sounds like a problem where the MySQL driver in PHP5.3 has trouble connecting to the older MySQL version 4.1. Have a look on http://www.bitshop.com/Blogs/tabid/95/EntryId/67/PHP-mysqlnd-cannot-connect-to-MySQL-4-1-using-old-authentication.aspx
There's a similar question here with some useful answers, Cannot connect to MySQL 4.1+ using old authentication
SELECT `User`, `Host`, Length(`Password`) FROM mysql.user
This will return 16 for accounts with old passwords and 41 for accounts with new passwords (and 0 for accounts with no password at all, you might want to take care of those as well).
Either use the user managements tools of the MySQL front end (if there are any) or
SET PASSWORD FOR 'User'#'Host'=PASSWORD('yourpassword');
FLUSH Privileges
I had this problem too. But this was because of another reason.
My password began with character $... e.g. $MyPassword
I've changed it to #MyPassword and the problem is solved.
Easy.
open xampp control panel -> Config -> my.ini edit with notepad. now add this below [mysqld]
skip-grant-tables
Save. Start apache and mysql.
I hope help you
Here maybe?
I believe that the code should be:
$connect = new mysqli("host", "root", "", "dbname");
because root does not have a password. the (using password: YES) is saying "you're using a password with this user"
TIP:
comment out pid and socket file, if you can't connect to server..
mysql could be connecting with incorrect pid and/or socket file,
so when you try to connect to server trough command-line it "looks"
at the incorrect pid/socket file...
### comment out pid and socket file, if you can't connect to server..#pid-file=/var/run/mysql/mysqld.pid
#socket=/var/lib/mysql/mysql.sock
Most likely it is not identifying your user properly. root#localhost.
Select the Mysql version your MAMP is using.
/Applications/MAMP/Library/bin/mysqldump -uroot -p db_name > test_db_dump.sql
I actually wrote an alias on my computer so I don't have to remember how to get to the bin directory.
alias mysqldumpMAMP='/Applications/MAMP/Library/bin/mysqldump'
Which allows me to run this:
mysqldumpMAMP -uroot -p db_name > test_db_dump.sql
You can save an alias in your bash profile ~/.bash_profile or ~/.bash_rc
May be there password is not set and you are passing password as argument.
Try ommitting password argument during connection..
Edit your privileges on PHPmyAdmin (WAMP), Note that your password and user name has not been created. So do create or edit it, that it might work with your sql connection in your php.
Hope it works
Try initializing your variables and use them in your connection object:
$username ="root";
$password = "password";
$host = "localhost";
$table = "shop";
$conn = new mysqli("$host", "$username", "$password", "$table");
I wrote a little Hadoop Client Java application, that lists all files in HDFS (unsecure) and all tables in Hive, and some more stuff. However, I need to change the Hadoop Username during runtime.
Setting the name via System.setProperty("HADOOP_USER_NAME", "testuser"); works fine for the first time I need this username. But when I want to change the username to e.g. System.setProperty("HADOOP_USER_NAME", "hdfs"); I get an exception (after setting the hadoop username to hdfs as shown above):
org.apache.hadoop.security.AccessControlException: Permission denied: user=testuser, access=READ_EXECUTE, inode="/app-logs/ambari-qa":ambari-qa:hadoop:drwxrwx---
What could be the problem here? Why can't I just change the username via the HADOOP_USER_NAME property whenever I want to?
EDIT
Can I just use UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser(username)); to change the user during runtime or are there some restrictions?
Because, you are connecting to HDFS or Hive using JDBC connection.
Till you close the existing connection , you cannot make one more connection from the same application to HDFS/Hive service .
I am trying to configure DataSources with WebLogic 10.3 and database is MySQL Server 5.5 , On entering the following
Driver Class Name ="com.mysql.jdbc.Driver"
url =jdbc:mysql://localhost:3306/weblogicdb
Database User Name =root (User name of Database MySql Server)
Password =123(Password name of Database MySql Server)
Confirm Password =123
and on clicking TestConfiguration, I get the following error.
Connection test failed.
Message icon - Error Unknown database 'weblogicdb'<br/>com.mysql.jdbc.SQLError.createSQLException(SQLError.java:930)
<br/>com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2864)
<br/>com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:806)
<br/>com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3263)
<br/>com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1176)
<br/>com.mysql.jdbc.Connection.createNewIO(Connection.java:2638)
<br/>com.mysql.jdbc.Connection.<init>(Connection.java:1525)
<br/>com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:260)
<br/>com.bea.console.utils.jdbc.JDBCUtils.testConnection(JDBCUtils.java:505)
<br/>com.bea.console.actions.jdbc.datasources.createjdbcdatasource.CreateJDBCDataSource.testConnectionConfiguration(CreateJDBCDataSource.java:369)
<br/>sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br/>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
<br/>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br/>java.lang.reflect.Method.invoke(Method.java:597)
<br/>org.apache.beehive.netui.pageflow.FlowController.invokeActionMethod(FlowController.java:870)
<br/>org.apache.beehive.netui.pageflow.FlowController.getActionMethodForward(FlowController.java:809)
<br/>org.apache.beehive.netui.pageflow.FlowController.internalExecute(FlowController.java:478)
<br/>org.apache.beehive.netui.pageflow.PageFlowController.internalExecute(PageFlowController.java:306)
<br/>org.apache.beehive.netui.pageflow.FlowController.execute(FlowController.java:336)
<br/>org.apache.beehive.netui.pageflow.internal.FlowControllerAction.execute(FlowControllerAction.java:52)<br/>...
I was looking into many blogs and previously asked questions, where they it could be because of username and password being incorrect. But that is not the issue in my case, I have rechecked it. on using the same username and password, I was able to log into my MySQL database.
Kindly help me in configuring the system.
Error stack clearly says that:
Message icon - Error Unknown database 'weblogicdb'
It seems you have input a wrong database name.
You might be succeeding with username/passwords to MySQL server.
But the server might have multiple databases in it and 'weblogicdb' is not the correct database name you are trying to connect to.
To see what databases the MySQL Server has in it, execute the following command either using java or any other MySQL clients like MySQL command line, SQLyog, PHPMyAdmin etc.
show databases();
This statement should result all the databases available.
Identify the appropriate one for your program and use the same in your code.
To connect through java to execute the above statement, db url should be:
url =jdbc:mysql://localhost:3306/?user=usernamevalue&password=passwordvalue
Java 1.7
Spring 3.1.1 with Spring-WS 2.1.1
Joda
Hibernate 3.6
MySQL 5.0.51a
Maven 3
Tomcat 7
Eclipse 3.7
Greetings all...
Just another 'Access denied for user 'foo'#'localhost' error being thrown by my webapp, but with a twist.
I run both an instance of MySQL on my (duh) local machine for development, and another on my remote server.
Both instances have a database 'mydb' and two tables with identical names and structures.
On the local instance I use root.
On the remote machine I have issued the following sequence:
CREATE USER 'fubar'#'localhost' IDENTIFIED BY 'mypwd';
CREATE USER 'fubar'#'%' IDENTIFIED BY 'mypwd';
CREATE USER 'fubar'#'my.remote.server.com' IDENTIFIED BY 'mypwd';
GRANT ALL ON mydb.* TO ' CREATE USER 'fubar'#'localhost' IDENTIFIED BY 'mypwd';
GRANT ALL ON mydb.* TO ' CREATE USER 'fubar'#'%' IDENTIFIED BY 'mypwd';
GRANT ALL ON mydb.* TO ' CREATE USER 'fubar'#'my.remote.server.com' IDENTIFIED BY 'mypwd';
FLUSH PRIVILEGES;
I've confirmed with a 'select * from mysql.db' that three new rows appear and that all the appropriate fields have 'Y' values.
On the local machine from within a Command Prompt pane I can issue:
mysql -u fubar -p -h my.remote.server.com ,
reply with the password and get connected to the remote db.
Executing my java program fails with the famous
'Access denied for user 'fubar'#'localhost'
when url is adjusted to point to remote server
Using the following as part of my db.properties file in my Eclipse project:
hibernate.connection.url=jdbc:mysql://localhost:3306/mydb
hibernate.connection.username=root
hibernate.connection.password=myrootpwd
execution works great
execution fails with the dreaded error when using this:
hibernate.connection.url=jdbc:mysql://my.remote.servier.com:3306/mydb
hibernate.connection.username=fubar
hibernate.connection.password=mypwd
So I am stumped. How is that I can connect directly to the remote instance of MySQL server using the command line but not in my db.properties file?
TIA,
Still-learning Stev
I got into the same issue and its the wrong password that created the whole issue...
You can use the standalone java program code in the below link to test your connection and make sure it works first...
http://www.mkyong.com/jdbc/how-to-connect-to-mysql-with-jdbc-driver-java/
I have a running local instance of PostgreSql on a linux machine. When I use psql command from the shell I success to log in without any problem. I need to connect to the PostgreSql via the JDBC, but I don't know what exactly should I pass as url parameter to DriverManager.getConnection().
It should start with jdbc:postgresql: but what's going next?
I was told by the system group that a database with was created like user name. e.g. if my user is jutky a db named jutky was created, but when I try to open a connection to jdbc:postgresql:jutky I get an error
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "jutky"
:(
Additional info
When I login via the psql I'm not prompted for the password, so when I try to login via JDBC I pass an empty string as a password - is it correct, or should I pass null or something?
When I type psql --help in the shell I see among the rest this line:
Connection options:
-h, --host=HOSTNAME database server host or socket directory (default: "/var/run/postgresql")
So I understand that I connect to PostgreSql via a socket directory, does that matters something to the URL string in the JDBC?
EDIT
First thanks for the answers.
Second: its not first time I'm using JDBC and in particular not the first time I'm connecting to the PostgreSql from JDBC, so I know the general rules and I have read the documentations. However in the described case I'm not sure how exactly should I construct the connection string if the instance is running via the socket directory and what password should I provide. Because when I login via the psql I'm not prompted for password at all.
Thanks in advance.
In addition to other answers note that by default Postgres is configured to accept connections via Unix sockets with authentication based on your operating system account, that's why psql works fine and doesn't require the password.
JDBC connections are made over TCP/IP with password authentication, so you need to modify pg_hba.conf accordingly. For example, this line allows TCP/IP connections from the same machine to all databases for all users with password authentication:
host all all 127.0.0.1/32 md5
After adding this line jdbc:postgresql:databasename should work.
EDIT: You can't create a JDBC connection over Unix socket since PostgreSQL JDBC driver can only work over TCP/IP. The password you use when creating JDBC connection is the password assigned to your user. If you don't have it, you can assign it, for example, using ALTER USER command. See 19.3. Authentication methods.
See also:
19.1. The pg_hba.conf file
It's all explained in official documentation.
This is the relevant part:
String url = "jdbc:postgresql://localhost/test?user=fred&password=secret&ssl=true";
Connection conn = DriverManager.getConnection(url);