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

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.

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.

phpmyadmin connecting to database

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.

Php mysql connection to the Cpanel db

how to connect cpanel db from Localhost.
i know connect from localhost. But i need to connect from server.
i am trying like this
<?php
mysql_connect("208.91.199.141","username","password") or die(mysql_error());
mysql_select_db("db");
?>
i get an Error
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'glansade'#'49.206.54.187' (using password: YES) in C:\xampp\htdocs\calendar\db_server.php on line 2
Access denied for user 'glansade'#'49.206.54.187' (using password: YES).
How to solve this....? Please Help me. Thanks
Go to RemoteMysql from cpanel
you have to add %.%.
Then you will be able to connect from remote Db.
You will not want to add %.% to Remote Database Access Hosts as it is a security concern. The %.% is a wildcard and using that wildcard in access hosts like that will expose mysql to the internet and the possibility of unauthorized database access is greatly increased.
Based on your error, the IP you are connecting from is 49.206.54.187. You will want to use this IP address in Remote Database Access Hosts. If you do not know the IP address to use, you can check your IP at http://cpanel.net/myip
I also see that you are connecting with your cPanel account username. While this should work, it is the preference of many to setup a separate account for each Database. To accomplish this, follow these instructions.
In cPanel, select MySQL Databases
In the Databases section, under "MySQL Users", create a New MySQL user.
After creating that user, add that user to the Database in the section "Add User To Database"
Make sure to select all privileges.
Thanks!
I'm not an expert, but I think you should try :
mysql_connect("localhost","username","password") or die(mysql_error());
Instead of :
mysql_connect("208.91.199.141","username","password") or die(mysql_error());

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

Why do I get "Access denied for user 'root'#'myhostname" when connecting to my database in PHP?

I have set up an Apache server on mandriva linux 2010.1. But the problem is whenever I'm trying to connect with the database, it's giving me the following error:
Error:Database error: SQLSTATE[28000]
[1045] Access denied for user
'root'#'myhostname' (using password:
YES)
Normally for a web application, you shouldn't connect to the database as root. However you tagged your post as [phpmyadmin] so I assume your issue is with, well, phpMyAdmin, in which case you might be connecting as root.
If this is the case, I see that you mentioned myhostname in your error message. Have you tried connecting to localhost instead? Sometimes the MySQL root user cannot connect from remote hosts.
you need to set some configuration variables for phpmyadmin to work:
http://www.phpmyadmin.net/documentation/Documentation.html#config
GRANT ALL PRIVILEGES ON *.* TO monty#localhost
IDENTIFIED BY 'indian' WITH GRANT OPTION;
Replace your username and password and execute it in your phpmyadmin by selecting your database.
Take a look at "5.4.7. Causes of Access-Denied Errors" in the MySQL online documentation and Using authentication modes" in the PHPMyAdmin documentation.

Categories