How can I connect remote mysql db from my local? - php

When I try to connect to the remote mysql db from my local XAMPP php, it says,
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host
'testhost.testserver.com' (11004) in D:\xampp\htdocs\cvsprojects\test\initdb.php
on line 24
I am sure the mysql host, user name , password are correct to connect.

Your remote MySQL server must allow remote clients to connect. I Am quoting this from a web page
you need to have remote access privileges to the MySQL server. You must use your client IP address or a %-wildcard in the Host column of the mysql.user table next to your username. For more information on connecting to a remote MySQL server see the MySQL documentation (Security and GRANT topics).
Moreover, make sure your system can access the network your remote server is hosted on. After that its plain simple connection settings or strings as some call it.

Related

How can I access MySQL databases created on a different server on phpMyAdmin?

I have 2 different MySQL databases, one created on a live server and another on a local XAMPP server. For some reasons, I can't access the databases on the live server (using phpMyAdmin) but I have access to the database files in var/mysql. So, I'm trying to recreate the databases on the local XAMPP server and access them with phpMyAdmin.
I've tried 2 approaches.
Copying the database file into the mySQL data directory of the local server. With this, I can see the database on phpMyAdmin, but there are no tables populated in it. I'm guessing that's because of metadata inconsistencies.
Replacing the whole local mySQL data directory with the live mySQL data directory. But I'm getting connection problems.
MySQL said: Documentation
Cannot connect: invalid settings.
mysqli::real_connect(): (HY000/2002): Permission denied
Connection for controluser as defined in your configuration failed.
mysqli::real_connect(): (HY000/2002): Permission denied
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.
I've tried solutions like these, but I'm not still able to get access to the databases on phpMyAdmin.
Edit: I mean I don't have access to the databases either through phpyAdmin or command line mySQL. I just have access to the raw files.

retrieve data from mysql database using php from a different computer

I am a newbie on PHP . Can someone tell me how to connect and retrieve data from mysql database server using PHP from a different computer.
First of all, the MySQL server must accept remote connections.
Also MySQL's user that you use, must be allowed to log from PHP computer's IP.
Then you can simply connect from your PHP server changing configuration of connection by setting host parameter to MySQL server's IP instead of localhost.
Google for mysql remote connection in order to find information about how to configure it to accept remote connections.
Localhost in name suggest locally , you cannot access mysql database from another computer .
Copy the file and install , only then it will work.

Remote mysql connection

I work on a dictionary PHP project. Project owner has a dedicated server. They control server files via terminal. And they have a big database which include 370,000 words. In my program I want to connect to database. But the problem is that they don't want to upload my PHP project files to their server. Because they fear that the database maybe stolen by others. They say you can access our mysql server via some server info and they have send some information like this:
server ip : xx.xxx.xxx.xx
Port=3307;
UID=xxx;
pwd=xxxx
The thing that I know is if I want to connect a remote mysql server, The server owner must allow my IP address or upload project files to their server.
They say we don't have a ftp interface and can't allow remote IPs. You can successfully connect via mysql connector which written in php.
Is it possible to connect to the server only with this server information if the server owner not allow to my IP address for mysql connection?
No, it's not possible (with MySQL server default configuration) to connect to a remote MySQL server instance if your user id does not have permission to connect from the remote IP to MySQL server.
If you try to connect to local MySQL server these information would suffice but if you try to connect to a remote host with these information you might get an error like this:
"Connect failed: Access denied for user 'root'#'aa.bb.cc.dd' (using
password: YES)"
This indicates that your user id does not have permission to connect to the MySQL instance from this remote IP address.
But again you can try to connect to the remote MySQL server and get a connection back. It all depends on the remote MySQL server configuration.
The above information is enough to connect to MySQL server through php.
But if the server owner, has disallowed your IP for MySQL port, then you will not be able to connect.
But maybe that isn't the case, the IP disallowing can be application specific.
eg. they can disallow outside IPs to access there FTP and SSH but their MySQL port can be open for outside IP addresses hence can be accessed by you.

Cannot access MySQL database from my website, but can access via browser?

I'm trying to hook up my website to my MySQL database on my new webhost, and I'm running into a few issues I can't resolve.
If I navigate to mywebsite.com/phpmyadmin/, I'm presented with an HTTP authorization, and upon successful entry of that, my PHPMyAdmin login page, where I can log-in as my user and see my databases. Yet, if I try to connect via PHP through my website, I receive the error:
SQLSTATE[HY000] [2005] Unknown MySQL server host 'mywebsite.com/phpmyadmin' (11)
My connection info is:
$this->dbh = new PDO('mysql:host=mywebsite.com/phpmyadmin;dbname=mydb;charset=utf8','me','myPassword');
I'm running LAMP on Ubuntu 14. Is there any particular reason this is failing?
PHPMyAdmin is a database client application, not a database server.
You need to provide connection information to your database server (which will probably be localhost)
You need to connect to the mysql server rather than the phpMyAdmin interface (won't work).
In this case it's you will use localhost (Really). Why? because localhost just points to the server's local IP. You can also point it to any hostname which points to the server's IP so it knows which server to connect to! :)

Connecting remote server mysql database to localhost

How can I connect my localhost PHP files to my remote server MYSQL database?
For example: if we download WordPress, and it gives us an option to login, so that our login credentials are saved with WordPress but still our localhost files connects to that database.
How do I do that?
Thanks.
If you want your PHP code to connect to a remote MySQL database, you just have to specify that remote host when calling the function that connects to MySQL.
For example, when calling mysql_connect(), don't specify localhost as first parameter -- but your real remote host.
Same with mysqli::__construct() or PDO, of course.
A couple of notes :
Your remote host must accept connections to MySQL (think about the firewall)
Your remote MySQL database server must accept connections from non-localhost
Sending queries, and fetching results, to/from a far away server will be a lot slower than doing so on localhost !
mysql_connect(SQL_IP, SQL_NAME, SQL_PASS);
Well when you install Wordpress set the host to be the IP of your remote server. If this isn't what you're looking for, please reword your question. If you're not using word press, check ou the PHP documentation for mysql_connect. The first parameter is the host. Enter the IP or hostname of your remote server here. And then follow that with your username and password.
mysql_connect('remote-host', 'myuser', 'mypassword');
Note: Some hosts do not allow remote connections to MySQL. Check your remote server doesn't have 3306 firewalled or only instructed MySQL to bind it to 127.0.0.1.

Categories