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
Easy.
open xampp control panel -> Config -> my.ini edit with notepad. now add this below [mysqld]
Save. Start apache and mysql.
I hope help you
I solved in this way: I logged in with root username
I created a new user with
then I created the database
I granted privileges for new user for this database
Then I logged out root and logged in new user
I rebuilt my database using a script
And that's it.. Now from php works without problems with the call
Thanks to all for your time :)
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...
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
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
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