When I am connected to the internet, I can connect to my local MySQL server with my public/internet IP address, using MySQL workbench.
However, using the same parameters, I can not connect to the same MySQL server from a website running on PHP. I use the code line below:
new mysqli("41.58.XX.XX", "username", "mysql_pswd", "db_name");
I get the following error message:
(HY000/2003): Can't connect to MySQL server on '41.58.xx.xx'
Note: My configuration includes granting all privileges to the user on all host '%'
Please how can I do this correctly?
Related
Web server at 172.168.40.14
Mysql server at 172.168.40.13
There is a user#172.168.40.13 created at 172.168.40.13 MySQL server and it has plenty permissions on database inspeccion
Trying to connect from webserver
$this->pdo = new PDO('mysql:host=172.168.40.13;dbname=inspeccion;charset=utf8', 'user', 'pass');
results in the error:
SQLSTATE[HY000] [1044] Access denied for user 'user'#'172.16.40.14' to database 'inspeccion'
Why in the world is trying to connect to 172.16.40.14 when the code specifycally says conect to 172.16.40.13 ??
Thanks in advace
It is telling you that the 'user' at machine with ip '172.16.40.14' is not able to connect to the database.
It is not actually trying to connect to 172.16.40.14
To grant access to users from any ip or a specific ip, you can have a look at this post grant remote access of MySQL database from any IP address
You need to create a user#172.168.40.14 not a user#172.168.40.13 and give all permissions
I am attempting to connect to a remote MySQL server from my local machine virtualhost using the following code:
$conn = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die(mysql_error());
mysql_select_db($dbname, $conn) or die(mysql_error());
My problem is that I am unable to connect locally, receiving the error:
Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10060)
This is not the case when I upload the same PHP file to the server. I am able to query the database with no problems at all.
I am unable to connect via command line either, but I can access cPanel which rules out the chance of my IP being banned accidentally.
My local server is running PHP 5.2.9, the remote server 5.2.12
firewall of the server must be set-up to enable incomming connections on port 3306
you must have a user in MySQL who is allowed to connect from % (any host) (see manual for details)
The current problem is the first one, but right after you resolve it you will likely get the second one.
It is very easy to connect remote MySQL Server Using PHP, what you have to do is:
Create a MySQL User in remote server.
Give Full privilege to the User.
Connect to the Server using PHP Code (Sample Given Below)
$link = mysql_connect('your_my_sql_servername or IP Address', 'new_user_which_u_created', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db('sandsbtob',$link) or die ("could not open db".mysql_error());
// we connect to localhost at port 3306
I just solved this kind of a problem.
What I've learned is:
you'll have to edit the my.cnf and set the bind-address = your.mysql.server.address under [mysqld]
comment out skip-networking field
restart mysqld
check if it's running
mysql -u root -h your.mysql.server.address –p
create a user (usr or anything) with % as domain and grant her access to the database in question.
mysql> CREATE USER 'usr'#'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON testDb.* TO 'monty'#'%' WITH GRANT OPTION;
open firewall for port 3306 (you can use iptables. make sure to open port for eithe reveryone, or if you're in tight securety, then only allow the client address)
restart firewall/iptables
you should be able to now connect mysql server form your client server php script.
This maybe not the answer to poster's question.But this may helpful to people whose face same situation with me:
The client have two network cards,a wireless one and a normal one.
The ping to server can be succeed.However telnet serverAddress 3306 would fail.
And would complain
Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10060)
when try to connect to server.So I forbidden the normal network adapters.
And tried telnet serverAddress 3306 it works.And then it work when connect to MySQL server.
I've got problem with connection to mysql base via php, i can connect to database via mysql client application without any problems but mysql_connect all the time showing access denied.
I've got local mysql server on windows
static ip
opened port 3306
added port rules in windows firewall (also tried with firewall disabled)
mysql user with all granted (flushed privileges)
binded address in my.ini to my server ip
and f.e. application dbforge studio for mysql (mysql client app) can connect without any problems and mysql_connect in php can't.
$sql_connect = mysql_connect("mystatic_ip", "user", "pass");
echo mysql_errno() . ": " . mysql_error(). "\n";
$sql_selected = mysql_select_db("database");
Another strange thing is that i'm trying to connect from different network/machine and the error displays 'localhost'
1045: Access denied for user 'root'#'localhost' (using password: YES)
Any suggestions?
I want to connect with external database using PHP. But, it gives this error
Warning: mysql_connect(): Can't connect to MySQL server on 'SERVER_IP_ADDRESS' (110) in /home/<username>/public_html/index.php on line 7
Can't connect to MySQL server on 'SERVER_IP_ADDRESS' (110)
Here is my code.
define("_CONFIG_DB_HOST", "SERVER_IP_ADDRESS"); /* database host name */
define("_CONFIG_DB_NAME", "DATABASE_NAME"); /* database name */
define("_CONFIG_DB_USER", "DATABASE_USERNAME"); /* database username */
define("_CONFIG_DB_PASS", "DATABASE_PASSWORD"); /* database password */
$con = mysql_connect(_CONFIG_DB_HOST,_CONFIG_DB_USER,_CONFIG_DB_PASS) or die(mysql_error());
mysql_select_db(_CONFIG_DB_NAME,$con) or die(mysql_error());
I've also added entry for Remote Database Access Hosts in Host Server
Please guide me if I'm doing anything wrong.
Make sure DATABASE_USERNAME has access from you host (the machine running this script) has access to DATABASE_NAME on SERVER_IP_ADDRESS.
When you grant access on database to use you would use USERNAME#HOST form. Here the HOST means the host where this USERNAME would be connecting from. Usually we keep it localhost. becasue we want to connect by a user who is in localhost according to mysql server. But your local host is not mysql servers localhost. That's why that host part needs to be changed.
My php code fails to connect to the mysql database on my web server. I get the following error:
mysql_connect(): Lost connection to MySQL server at 'reading initial
communication packet', system error: 110 in filename at line 71.
The same code works fine when run from my development machine pointed at the mysql database on the server I'm trying to run this from (I copied the file up to the server and I'm trying to run it via ssh on that server). I have verified that the mysql user in the script can connect to the database from the server by running mysql from the ssh command line on that server using the same user name and password as specified in my php script.
here is my code:
function jsw_set_cnxn($env){
global $env;
$cnxn = mysql_connect($env['db_svr'], $env['db_usr'], $env['db_pwd'])
or die ('DB Connection Error: ' . mysql_error());
mysql_select_db ($env['db'], $cnxn);
return $cnxn;
}
I've seen this error caused when using the servers IP address when it expects localhost as the server address.
This is because the server is the machine mysql expects but the wrong host coming in. Try using localhost.