I have a database that I want to transfer to my remote server from localhost. The file being too big, I wrote the code to copy the table. But the problem the connection is not successful. My code looks like this.
$server_conn=mysqli_connect($db_host,$db_user,$db_pass,$db_name);
if (!$server_conn) {
die("Server Connection Fail: " . mysqli_connect_error());
}
Where $db_host is the ip address of my server.
When I load the script the error I get is
Server Connection Fail: Access denied for user db_user#'117.202.126.83' (using password: YES)
The credentials are correct, the host is correct, and the weirdest part is 117.202.126.83 is my IP address.
I don't know how is it ignoring the host and taking my connection IP address for host. Even when I give the db_host as the IP address of my remote server.
Also, I am running the script using Easy PHP 14.1 running APACHE 2.4.7,MYSQL 5.6.15 and PHP 5.4.24.
What am I missing?
UPDATE: I am not sure if I was stupid or if the hostgator instructions were.
They ask us to add the cpanel username followed by an underscore before the database name and database username.
In the cpanel, the cpanel username is prefixed by force to all user and db names. So in my case, I had the variables as cpanelUsername_cpanelUsername_databaseName and so on.
Thank you guys for your replies
Go to the cpanel where your phpMyAdmin has the access.
Click on Remote MySQL
Add the access host (Your local IP which is running the script)
Then you can get access to remote mysql server.
You can then test the connection using MySQL Workbench ()
are you sure you use the proper external database hostname/ip?
Related
I'm developing on 'server1'.
I need to save the data processed on this server to the 'server1' database.
However, I also need to save some data to an external 'server2' database.
The problem is that when I connect to the database of the other server I get a fairly weird error.
Error code: 1045
Error message: Access denied for user 'server2-username'#'server1-name' (using password: YES)
Why does 'server1' appear in the error message?
To me, the message says this: "hey, I can't find the 'server2-username' on 'server1' database". Am I correct? Why does say that, when I'm connecting to 'server2'?
$connection = new mysqli('server2-ip', 'server2-username', 'server2-password', 'server2-database');
if($connection->connect_errno) {
echo $connection->connect_errno;
echo $connection->connect_error;
}
Any idea how should I connect to 'server2'? Or what should I check?
This is the first time I want to connect to another server database. I haven't done this yet, and I don't know what's wrong.
This error mean 'server2-username' try to connect from 'server1-name' and not succeed.
Please check permissions user2 on server2 for connect from remote host
It demands an account which matches the connecting user#hostname, which is server2-username#server1-name... it's just that the web-server runs on the same host server1-name as the mySQLd on server1-name. This may appear confusing, but the hostname comes from where the script runs.
You'd need to add user server2-username#server1-name to the mySQLd on server2-name... and if you can't get that account set up, most commonly there's a JSON API available as a web-service; exporting/importing data to any format would also be an option, if they wish to import themselves.
SSL tunneling could even connect through local loop-back interface 127.0.0.1 on :3307 (the problem isn't bind-address = 127.0.0.1, but that there is no such user#hostname available):
shell_exec("ssh -fNg -L 3307:server2-ip:3306 server2-username#server2-ip");
$connection = new mysqli('server2-ip', 'server2-username', 'server2-password', 'server2-database', 3307);
However, either getting that remote user account setup or using an API might rather be the suggested options, because the SSL tunnel created with shell_exec() might be closed at any time, which all needs to be tested & handled accordingly. The error message would at least be server2-username#server2-name or server2-username#localhost, when tunneling into it.
I am trying to access to the database of my live website from localhost. My website is working on cpanel hosting.
I created database and added user to that database but can not connect to this database from my localhost .
this is the code of database information
<?php
$conf['dbuser']='admin_root';
$conf['dbpass']='rootroot!##$';
$conf['dbname']='bsaiiian_os';
$conf['dbhost']='example.com';
$conf["title"]='DEMO';
?>
I think the problem is from $conf['dbhost'] variable where I'm putting the url of my site and not sure if that is right.
When I'm uploading my script to the hosting and put
$conf['dbhost']='localhost';
the connection is established .
this is error message:
Connection failed: No connection could be made because the target machine actively refused it.
Due to security reasons cPanel's MySQL requires that you allow your IP in order to have access.
This is done through:
cPanel -> Remote MySQL Connection
You need to navigate there and allow your local computer's IP in order to make the connection.
Side Note: This stands true for all IPs, even the server's one that your account is hosted on. You will see your cPanel account's IP already present in there - this is to allow access to MySQL for any files from your cPanel account
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.
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.
Help!
I have a PHP (PHP 5.2.5) script on HOST1 trying to connect to an MySql database HOST2. Both hosts are in Shared Host environments controlled through CPanel.
HOST2 is set to allow remote database connections from HOST1.
The PHP connect I'm using is:-
$h2 = IPADDRESS;
$dbu = DBUSER;
$dbp = DBPASS;
$DBlink = mysql_connect($h2, $dbu, $dbp);
This always fails with:-
Access denied for user '<dbusername>'#'***SOMESTRING***' (using password: YES)
nb: SOMESTRING looks like it could be something to do with the shared host environment.
Any ideas???
BTW: I can make remote connections to HOST2 from my laptop using OpenOffice via ODBC, and SQLyog. The SQLyog and ODBC settings are exactly the same as the PHP script is trying to use.
somestring is probably the reverse-lookup for your web-server.
Can you modify privileges from your cPanel? Have you done anything to allow access from your workstation (ODBC)?
The error-message seems to indicate that you have network-access to the mysql-server, but not privileges for your username from that specific host.
If you're allowed to grant privileges for your database, invoking:
GRANT SELECT ON database.* TO username#ip.address.of.host1 IDENTIFIED BY 'password'
might work for you. I just wrote this out of my head, you might want to doublecheck the syntax in mysql-docs.
Have you read the MySQL documentation on Causes of Access denied Errors?
Have you contacted support for your hosting provider? They should have access to troubleshoot the database connection. People on the internet do not have access.
Do you need to specify the database name? Your account might have access to connect only to a specific database. The mysql_connect() function does not allow you do specify the database, but new mysqli() does. I'm not sure if this is relevant -- it might allow you to connect but give you errors when you try to query tables that aren't in your database.
Are you sure you're using the right password? MySQL allows each account to have a different password per client host. Admittedly, this is not a common configuration, but it's possible. Your hosting provider should be able to tell you.
Just some ideas:
HOST1 does not have remote access to HOST2 (shared host is disallowing)
MySQL account does not have access from HOST1 (IP address specified on account creation, or wildcard)
Edit:
In response to your comment, I meant that HOST1 cannot get to the MySQL port on HOST2. Web services will work, of course, because port 80 is open to the public. As another user pointed out though, you are getting a response, so you are reaching it. I would try specifying the DB, and double checking the account creation command you ran.
For the second piece, I meant this: http://dev.mysql.com/doc/refman/5.0/en/adding-users.html
You can specify what host the username can connect from. If it isn't set to HOST2's IP or the wildcard, HOST2 can't log in with those credentials.
The error message means that you can contact the mySql server, but the user you are trying to log in as, does not have access.
Either the user does not have access at all, or it has access locally, but not from the host you are connecting from.
You should try to use the hostname and port like $h2 = IPADDRESS:3307;