Access denied for Database User at goDaddy website - php

I am trying to view my website from godaddy. The domain name is registered on somewhere else and hosting is from godaddy. After changing DNS settings, I cretae my db in godaddy and import all tables in it. After that, i created a username and give it to all previleges. Then, when i tried to connect to database, i am facing error
Access denied for user 'myusername'#'ip-166-62-28-82.ip.secureserver.net' (using password: YES)
db.php
<?php
$conn = mysql_connect("166.62.28.82", "myusername","mypassword", "arikai2_2" ) or die(mysql_error());
mysql_select_db("arikai2_2");
?>

Where did you get the dbhost value from?
In your hosting panel, there should be somewhere a section where you can get the right details about connecting to your database server and its databases.
If you are using the classic goDaddy hosting, you can find this info in the:
Databases > MySQL Section > Actions > Details
The dbhost is down at the bottom of this screen: Hostname

Make sure that the mysql host is correct. You can contact your hosting provider to help you getting the proper host for your connection string.

Anyone having issue even after correct username,password and database name, reset your database user's password and update it in your mysqli connection code. This is weird but it worked for me.

Related

PHP can't connect to the MySQL Database Access denied

I get this error message
Access denied for user 'user'#'localhost' (using password: YES)
I tried to access with the root, the admin account and some user account I made for the web visitors with a few privileges. Those users (admin and web user) were created with cPanel.
I'm testing the connection with this simple code to avoid making a mess with functional code.
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
I stumbled with this explanation but it doesn't work either
Your cPanel username and password can be used to connect to your databases (as well as your cPanel). If you're connecting to your database using your cPanel username and password, you can reset your cPanel password to ensure you are using the correct username and password.
If you setup a MySQL username and password specifically for accessing a database, you'll want to ensure you are using the correct username in your php scripts. For example, MySQL usernames are always in this format:
cpanel-username_mysql-username
If your cPanel username is userna5 and you created a database username of dbuser1, then the actual database username would be:
userna5_dbuser1
Edit: i already assigned the users to a database and their privileges. I'm working on a remote server
I faced the exact same issue on one of my employees' Windows PC.
The issue was caused duo the fact that his private repositories folders including those who were used by Docker were located in C:\Users{user_name} folder.
At some point in time, Windows prevented Docker's access to these folders.
Solution: relocation the folders outside the Users folder solved the issue.
Are you running the code on your local machine or on the remote server. If it's running on your local machine you'll have to replace 'localhost' with the ip address of the server eg. '123.123.123.123'
If you are using the online server after creating the user and the database make sure you give the user privilege to access the database
If you are accessing MySQL database from the remote server, you will have to use server IP address for MySQL host. Also you will have to allow your remote server IP address in "Remote MySQL" under your cPanel otherwise you will not be able to access your database remotely.

PHP MySql (1045) Access Denied For User

I've tried to search for an existing answer to this problem, but the answers I find have not worked thus far.
I've been attempting to use PHP to connect to a MySql database. My web host uses cPanel on Linux. The code I'm using to do this seems standard enough:
$mysqli = new mysqli("localhost", "cPanelUsername_dbUsername", "dbPassword", "cPanelUsername_dbName");
I've been getting the following error:
Failed to connect to MySQL: (1045) Access denied for user 'cPanelUsername_dbUsername'#'localhost' (using password: YES)Access denied for user 'cPanelUsername'#'localhost' (using password: NO)
"localhost" is the host server where the MySql server is located (it seems like this works)
"cPanelUsername" is my cpanel username
"dbUsername" is the database user, which I added to the database with all permissions granted
"dbPassword" is the database password for dbUsername
"dbName" is the database name
I ended up adding my cPanel username before the dbName and dbUsername after searching for answers to this issue elsewhere.
It looks like I have everything set up correctly but it's not connecting (with the error above). I don't have any direct control over the server that I wouldn't have to ask my web host about, which may take a few days to get sorted out. Do I have something wrong with my connection code?
First check the database that you gave the proper user access to your database, which is given from Add User to databases from Mysql database section in cpanel.
after that check it again,
first try normal connection code in php,
$con = mysql_connect("localhost","cpanel_username","cpanel_password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
In cPanel, make sure that:
The database user cPanelUsername_dbName exists, with the password dbPassword
The database you want to use exists.
The user cPanelUsername_dbName is allowed to access the database.
The user cPanelUsername_dbName is allowed to access the database from localhost, 127.0.0.1, and the IP address of your server.
Your MySQL connections may use 127.0.0.1 or the IP address of your server, and MySQL will reject the connection if access isn't granted for the specific IP address used.
check the database name spelling at your phpMyAdmin. Usually the name is in format user_dbname.
For example:
cpanel username: jack,
database created: student
In your php script, the dbname should be jack_student
This worked for me:
Depending on what MySQL version you have, make sure you have matching password and hostname on your PHP file, config.inc.php file.
If you need to change the password for MySQL 5.7.6 and later:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
If you are trying to access your localhost server from a different machine i.e. (emulator, another computer), make sure you are using the actual IP address of the the localhost, DO NOT USE localhost as the hostname. Because this is like telling the machine to connect to itself - but the server is on a different IP address.

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

Reasons for MySQL authentication error: "Access denied for user 'xxx'#'yyy'"?

What possible reasons could exist for MySQL giving the error “Access denied for user 'xxx'#'yyy'” when trying to access a database using PHP-mysqli and working fine when using the command-line mysql tool with exactly the same username, password, socket, database and host?
Update:
There were indeed three users in the mysql.user table, each one with a different host (but with the same hashed password), one was set to localhost, one to 127.0.0.1 and one to the machine’s host name. Deleting two of them and changing the host of the third to “%” had only one effect: now the access is denied using the command-line tool also.
I did do a
select user();
before that in the command line and it yielded the same xxx#yyy that were denied in php.
Sometimes in php/mysql there is a difference between localhost and 127.0.0.1
In mysql you grant access based on the host name, for localusers this would be localhost.
I have seen php trying to connect with 'myservername' instead of localhost allthough in the config 'localhost' was defined.
Try to grant access in mysql for 127.0.0.1 and connect in php over 127.0.0.1 port 3306.
In case anyone’s still interested: I never did solve this particular problem. It really seems like the problem was with the hardware I was running MySQL on. I’ve never seen anything remotely like it since.
After I read your update I would suspect an error in/with the password.
Are you using "strange" characters in your PW (something likely to cause utf-8/iso encoding problems)?
Using % in the Host field would allow the user to connect from any host. So the only thing that could be wrong would be the password.
Can you create another user. whith the "grant all on all for '...'#'%' identiefied by 'somesimplepw'" syntax, and try to connect with that user?
Don't forget to 'flush privelidges'
For info on how to create a new user klick here
Today the FTP service of my web hosting provider is having some trouble, so I decide to realize a local virtual webserver for working on my website. I have installed EasyPHP 14.1 with phpMyAdmin and I have created my user and my database with tables.
First attempt: failed. I realized that the table I was looking for didn't exist. -> I solved creating the missing table.
Second attempt: failed. I realized that username that I set for my new user was diffrent from the username I used for my connection. -> I edited username.
Third attempt: failed. I realized that new database name was diffrent from database name I use for connection in my site. -> I edited db name.
Forth attempt: failed. I realized that between privileges of my new user there wasn't "Grant". I don't even know what "Grant" means, but let's try to enable it -> Added "Grant" privilege.
Fifth attempt: I win!
I hope my little adventure could help someone. =)

Categories