phpmyadmin connecting to database - php

I have a website that connects to a database and retrieves page content and all works fine. However, I then use the same database connection to connect to and retrieve user details for logging in to my site (2 tables but both in same database). However, I get the following error message when doing this.
Warning: mysql_query() [function.mysql-query]: Access denied for user 'username'#'localhost' (using password: NO)

The hint is in "using password NO" There is no password being sent - in fact it is only using username#localhost as the username so it looks like you don't have your credentials configured properly.
Check config.inc.php - http://wiki.phpmyadmin.net/pma/Configuration_storage

Well it's says that your password is not correct and that you haven't gained access. Can you please upload a code here ? if you're using localhost, then the username should be root .. try to change it and leave the password field empty for now.

Related

PHP script cannot connect to MYSQL database

I have a straight forward script that is trying to connect to a MySQL database.
When I run the script, I get the error:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in C:\xampp\htdocs\ShopSite\submitReg.php on line 16
Failed to connect.
The connection code is:
$server="127.0.0.1";
$db="shop";
$user="root";
$password="";
$conn=mysqli_connect($server,$user,$password,$db) or die("Failed to connect");
I can connect to phpMyAdmin and edit the database on there just fine. I am using XAMPP and running it locally.
When I go to user accounts, it says there is no password for root. I looked in the config file and there are no passwords set. I haven't set a password for anything.
I haven't went in and fiddled with settings, or created any new accounts. It was working fine (never used to get this problem), then it just started with this. I reinstalled XAMPP, still giving me this issue.
I don't get why it says using password "YES".
I've been at this for hours trying to fix it. I've looked through lots of threads. Not all necessarily apply to me, as I am running it locally, and haven't been going in and making new user accounts. Everything is default.
Before I reinstalled, I tried creating a new user account and giving it the necessary privileges. I gave it a password too. Didn't work.
I don't get why it is doing this, and am not knowledgeable enough to fix it myself. Any help is much appreciated, so that it can go back to connecting.
change
$server="127.0.0.1";
by
$server="localhost";
I used XAMPP for a while and it worked quite good for me,
i think the default password for your mysql server is not set to '', so i guess
if you change the root password and try accessing your database using the new password, it should work.
Updating the root password
To update the root use password, you have to go by these steps:
Open the XAMPP Control Panel
Click on the MySQL button
After the MySQL console has loaded, execute this query:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('pass');`
After that, change the $password variable to the new password which
is in this case pass
Adding a new user
You could also add a new user by executing this query:
GRANT ALL PRIVILEGES ON *.* TO 'new-user'#'localhost' IDENTIFIED BY 'password';
While the username is new-user and the password is password.
I hope this helps.

What's wrong with this MySQL connection?

I have setup a MySQL database and I am trying to connect to it from another website.
I get this error when I try to connect to it:
Connection failed: Access denied for user 'myUsername'#'localhost' (using password: YES)
It works fine when I do it in the same website where the database is hosted.
I tried this SQL query:
GRANT SELECT, DELETE, UPDATE ON database.myDatabaseName TO 'myUsername'#'localhost' IDENTIFIED BY 'myPassword';
But I got this error:
#1142 - SELECT,UPDATE,DE command denied to user 'Steve'#'localhost' for table 'myDatabaseName'
I went to the MySQL management in the built-in control panel where I modified permissions of Steve and added the Grant permission, however I still get the same #1142 error.
How can I fix this?
Thanks in advance.
Access denied for user 'myUsername'#'localhost' (using password: YES)
That's where the error is. It says you are attempting to connect to localhost with the username myUsername and a supplied password. However, usually on localhost, especially on windows systems, the user is Root and the password is not set, just an empty string. Check your username on your localhost and your password.

Could not connect to Google cloud SQL. Using PHP Google SDK

I did read this tutorial
https://developers.google.com/appengine/docs/php/cloud-sql/
I had created a Instance with name schoolnbd and my project id is myapplication-2013
After reading the tutorial I tried the code below
<?php
$dhost=":/cloudsql/myapplication-2013:schoolnbd";
$duser="root";
$dpassword="xxxyyy";
$database="schoolnbd";
$connection=mysql_connect($dhost, $duser, $dpassword) or die("Could not Connect to SQL Server Suleman");
$db=mysql_select_db($database, $connection) or die(" Check the Database Name from Config.php , wrong database entered ");
?>
But it is showing “Could not Connect to SQL Server Suleman”.
I had created one user by name suleman and made several changes , but still it is not connecting to SQL server, i am seeing same message.
I had tried doing many changes such as
try 1
$dhost=":/cloudsql/myapplication-2013:schoolnbd";
$duser="suleman";
try 2
$dhost="localhost";
$duser="root";
try 3
$dhost=":/myapplication-2013:schoolnbd";
$duser="root";
try 4
$dhost=":/cloudsql/myapplication-2013:myapplication-2013:schoolnbd";
$duser="root";
try 5
$dhost=":/cloudsql/myapplication-2013:myapplication-2013:schoolnbd";
$duser="suleman";
Error from the error log is
it is Showing mysql_connect(): Access denied for user 'root'#'localhost' (using password: YES) in /base/data/home/apps/s~myapplication-2013/1.371632998623546850/test.php on line 6
when I am using
$dhost=":/cloudsql/myapplication-2013:schoolnbd";
$duser="root";
i also faced the same problem, try without using password, it like this it will most probably work
$dhost=":/cloudsql/myapplication-2013:schoolnbd";
$duser="root";
$dpassword="";
but keep in mind , if you had set your root password then you should update root password, by typing this in console.
SET PASSWORD FOR 'root' = PASSWORD('');
If you are connecting using the root user, from AppEngine, you should not provide a password.

phpmyadmin username and password

I'm using phpmyadmin 5.1.36 through wampserver in my windows system. when i give http://localhost/phpmyadmin it directly gone into, showing databases what i did is i changed the password for the username root and phpmyadmin showed a message password successfully changed when i refresh the page it showed error
1045 - Access denied for user 'root'#'localhost' (using password: NO)
What i expect is the page which is asking for username and password. What should be done to get this.
Try checking your config file; there should be a line that says $cfg['Servers'][$i]['auth_type']. This should be set to either cookie or http if you want the username and password to be entered via login form.
You'll have to change phpmyadmin's configuration to use your new root account password. Since you change the mysql root user password, phpmyadmin can no longer log into the database, and is now essentially dead until you update its configuration file with the new password.
You need to set this behavior in the PMA's config.inc.php. You will need to set the auth_type to HTTP.

How to Connect to a Mysql database using PHP?

<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
This is the code I am using to check if I am able to connect to Mysql.
I am having problem connecting using this code. Should I change localhost to the name of the website?
I tried ("www.abc.com","login username", "password") even this is not working.
EDIT:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'mobile4_you'#'cl79.blahblah.com' (using password: YES) in /home/mobilew4/public_html/mysql.php on line 2 Access denied for user 'mobile4_you'#'cl79.blahblah.com' (using password: YES)
If you're using something like cPanel, it will prefix your username and your database with your username for cpanel, for example:
> cPanel login: foo
> Database User: bar
> Database: ey
Your database user will be foo_bar and your database will be called foo_ey
Localhost refers to where the database is running. If it's running on the same server as your PHP server localhost should work fine. What kind of problems are you having? Are you sure that your username/password is correct?
You should replace :
localhost by the name of the server on which your MySQL server is
if your MySQL server is on the same server as PHP, then it's localhost
username by the login that allows you to access your database
password by the corresponding password
Of course, this is supposing you actually have a MySQL server up and running, with a user account created on it.
Didn't you hosting company provide you with any information related to MySQL ? Using those informations, what error message does mysql_error() give ?
Do you have a mysql user which you've set up? You'll need to do that. In cPanel you can do it by clicking on MySQL databases, and on phpMyAdmin you can just add a new user on the start page. Put that users' username and password in.
You need to pay attention to the error, if any, reported by mysql_error(). This should give you some information you can use to diagnose the connection problem.
See this MySQL Forge wiki page about connection failure:
http://forge.mysql.com/wiki/Error2003-CantConnectToMySQLServer
Or this page from the MySQL Manual:
http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html

Categories