i want to connect my php application(here at my office) and my database is at my home,
mysql_connect('119.92.59.55','root','lester1992')
but they don't communicate each other(my comp & my office terminal), what maybe the posible problem?
here is the error i encountered.
mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
thanks in advance.
You need to give access permission in mysql to access from remote host.
GRANT ALL PRIVILEGES
ON database.*
TO 'user'#'your_office_ip_address'
IDENTIFIED BY 'newpassword';
To connect to a MySQL database, three things must meet:
Login
Password
Host
By default, root is configured to allow connections from the hostname localhost only. You can edit the table mysql.user and change root's Host to % to allow connections from any peer.
UPDATE mysql.user SET Host = '%' WHERE User = 'root';
Don't forget to run FLUSH PRIVILEGES after that change in order to make it take effect immediately.
In addition, your firewall and router must be configured to make connections to port 3306 possible. You can use an online test tool such as this one to check if your port 3306 is reachable.
By default, mysql is not allowing your user from your IP.
You want to allow access with a command similar to this (keep in mind this is very insecure):
GRANT ALL PRIVILEGES
ON database.*
TO 'root'#'119.92.59.55'
IDENTIFIED BY 'lester1992';
If you don't want to open your db for all ip's then you should assign rights to specific ip.
GRANT ALL PRIVILEGES ON db.* TO 'user'#'your_office_ip' IDENTIFIED BY 'newpassword';
Note: You can get your office ip by below link, it will show you your current ip:
http://www.whatismyip.com/
Related
I am trying to connect to an external server on a fresh MySQL install, but it just seems to timeout. Access has been granted by the other servers admin to the particular account and ip address. I try running the following:
mysql --host=hostname -u username -ppassword database
But just get the following:
ERROR 2003 (HY000): Can't connect to MySQL server on 'hostname' (110)
I have adjusted the following in my /etc/mysql/my.cnf file:
bind-address = 0.0.0.0
and restarted, but it didn't help. Any recommendations?
If you have checked that the firewall is letting MySQL traffic (usually port 3306) pass through and the service is running, the most probable cause is fine grained permission on the server. The user may not have been allowed to connect from any host, probably the permissions to connect are IP based or something similar.
I would try to use that code but not providing the password, like:
mysql -h hostname -u username -p database
and intert the password after that command (it will ask for it).
Also you could try to provide a port: --port=3306 for example.
You can also try to provide the protocol --protocol=TCP.
The only last idea that i have is that you dont provide the database and enter the database after you access the server...
sorry, can't do anything else from here with that data.
Try to grant the user to access database from the remote computer.
to do that:
mysql> GRANT all on database.* to 'username'#'%' IDENTIFIED BY 'user_password';
this is not recomended becouse this will allow connection to your mysql server from anywhere.
for allow connection to user in a certain ip address (we use 8.8.8.8 as example) use code below
mysql> GRANT all on database.* to 'username'#'8.8.8.8' IDENTIFIED BY 'user_password';
The problem lies in your permisions granted to your user. try changing permisions and hope it will help you .
I am using PHP and MySQL to make a database connection , problem is :
the web application project in my local machine when am trying connect to database remote server every thing is work fine
mysql_connect("x.xx.xx.x","username","password") or die(mysql_error());
when i deploy the web application in the remote server that have the mysql database and try to use that web application am getting no database error connection !! if i change database connection to :
mysql_connect("localhost","username","password") or die(mysql_error());
using localhost (127.0.0.1) instead of using ip address ever thing work fine , i have tried check /etc/my.conf file and add bind-address=192.168.15.15 and restart mysql server
still cant connect to database
any idea !!!
You need to check two things. First, make sure the port 3306 is open for connections. Second, if you're connecting remotely, you'll need to create a wildcard user (The host will be a percentage sign %). Take a look at the mysql.user table. If the user you're trying to connect to has a Host of localhost, you won't be able to connect remotely.
To create a new user:
CREATE USER 'newuser'#'%' IDENTIFIED BY 'password';
Give that user permissions, I suggest to only the database in question:
GRANT ALL PRIVILEGES ON your_database.* TO 'newuser'#'%';
Finally, reload the privileges:
FLUSH PRIVILEGES;
problem was i was enabling the SElinux , so i enabled httpd network with commad :
setsebool -P httpd_can_network_connect=1
I am using PHP and MySQL to make a database connection, the only change is that I am trying to access my remote server from my local computer using my server IP address.
mysql_connect("x.xx.xx.x","username","password") or die(mysql_error());
and the error I am getting is Unable to connect to the given host. The user has all privileges and rights.
Most default installs of MySQL only listen to the local machine.
Look for the bind-address setting in my.cnf on the server, and make sure it's listening on the IP address you're targetting. You may also need to ensure skip-networking isn't switched on!
Alternatively (and less securely!) the following will set it up to listen on all addresses - local and remote:
bind-address = 0.0.0.0
Before you try using PHP todo this. Open up your terminal or console and type the following:
$ mysql -u username -h x.xx.xx.x -p
then enter your password
Or on windows then type:
\path\to\mysql.exe -u username -h x.xx.xx.x -p
then enter your password
This will give you a more detailed response as to the authentication issue that's coming up. And you can be 100% sure that your remote login from your IP address works. If it works fine then its something in your PHP code that you're missing.
Try to add a user (USER-NAME) allowed to connect from the IP:
mysql> GRANT ALL PRIVILEGES ON *.* TO USER-NAME#IP IDENTIFIED BY "PASSWORD";
USER-NAME is the username that you would like to create (like 'widor')
IP is the public IP address of your remote connection (like '195.x.y.z')
Of course, limit the privileges you want to grant (ALL PRIVILEGES is probably not your choice)
1) Check which interface MySQL listen for connections, local (localhost, 127.0.0.1) or remote (0.0.0.0 or IP address). It's in my.cnf. http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
2) Check does your user have corresponding privileges. User that logs in from localhost can have different priveleges from remote one. For example 'user'#'localhost' and 'user'#'%'
I want to develop application that my database is not in the localhost, like this
$db['default']['hostname'] = "192.168.0.120";
But the application said this
A Database Error Occurred
Unable to connect to your database server using the provided settings.
can codeigniter using some server database instead of just localhost ?? or maybe something missing?
The server located at that IP address must be configured to allow remote MySQL connections, at least to port 3306 or whichever port MySQL has been configured to listen on.
In addition to BoltClock's answer above, it may also be necessary to grant the sql user proper permissions to connect remotely to the database.
Assuming that you are using MySQL, here are two (depending on how you would like it configured) different ways of performing that operation.
A) Allow remote connections for sql_user from IP 192.168.0.200:
mysql> GRANT ALL ON database.* TO 'sql_user'#'192.168.0.200' IDENTIFIED BY 'PASSWORD';
B) Allow remote connections for sql_user from any IP:
mysql> GRANT ALL ON database.* TO 'sql_user'#'%' IDENTIFIED BY 'PASSWORD';
Once done, you also need to flush/reload the privileges:
mysql> FLUSH PRIVILEGES;
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;