I've tried looking for this online, but am having trouble finding exactly what I am looking for.
Where I work we have one server that has multiple apache setups on it, all accessed by different subdomains, about 5 total (ex: abc.domain.com, xyz.domain.com, def.domain.com).
Problem is there is one mysql server, on a different physical server we need to connect to, that only allows connection from specific hosts (so say abc.domain.com). Whenever we try to connect to it from PHP, sometimes the login will fail because the user trying to login will come up on a different hostname. (ex user is root#xyz.domain.com, when root#abc.domain.com is the only one allowed). If the page is refreshed a couple time, it will eventually end up using the right hostname to login with and work fine.
My question is, is it PHP on the local server, or MYSQL on the remote server that determines what hostname the user is logging in from.
I know the easiest solution would be to add the other subdomains to the mysql server list of accepted hosts, but I have control over the PHP server, and the MYSQL server is a different department, and it would be much easier to come up with a solution on the PHP side of things.
Thanks
See here: How does mysql determine the hostname of its clients?. The MySQL server performs a reverse DNS lookup of the client IP. If you have multiple reverse entries, it's probably unpredictable which one will be used, which is why you see inconsistent results.
You should either remove the extra reverse DNS entries (they're not generally needed), or configure your permissions using the client IP rather than hostname.
Related
I have been working on setting up of php/nginx and mysql on seperate servers. i have multiple php servers but a single mysql server. I am connecting to mysql server from the private IP of these server.
To connect, I have used the private IP(PHP server's) which is 10.125.xxx.xxx as
10.125.0.0/255.255.0.0
and it connects. I do not know much about networking but I have understood that this does a complete match for the first 2 sets of number and uses the rest as wildcards. However, I have another PHP server with a private IP starting as 10.126.xxx.xxx. So to establish connection, I could create multiple users in the Mysql database and specify this seconnd Private host.
This approach may work, but I am wondering if I could just do something like
10.12%.0.0/<?subnet mask?>
Somehow allow all private IP's start with 10.12x.xxx.xxx
User configurations are for managing users / privileges / etc ONLY. Do not mix this with server connectivity / blocking.
Your MySQL server should accept calls only from your (designated) php servers.
Instead of allowing / denying at MySQL level,
Deny ALL
Allow 10.126.*
at server configuration itself. And keep as many users as you want to separately manage user calls from your different php servers.
And you can not do 10.12*.
Situation:
Php application with mysql database running on 2 sites
online -static ip X.X.X.X
localhost (not online most of time and dynamic ip)
application traffic is usually low <10 users.
what i need is that whenever a change is done to the online database, this change is pushed to localhost -if its online or when ever its available- and vise versa (any changes done locally is uploaded online to database when ever there is online connection).
is it possible to setup such replication by mysql ? or do i need to write a custom PHP that ping master server and once its available
thanks very much :).
Yes you can do this with replication. Just pick which server you want to be the master and have the second one send all of its changes to the main one then the main one could send its changes back.
Replication can be a bit daunting to set up but once its up and running its grate. http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html
Let's first analyze your question:
The problem of accessing MySQL with a dynamic ip.
This is very easy. Once you installed MySQL on a server with an ever-changing IP, what you can do is go to NO-IP, DynDNS or any other Dynamic DNS service and register for free with them. Once you've registered with them, you would get a client for your operating system. Install that and then you can access your MySQL server using a domain name.
Example:
Instead of having to access your server at 127.0.0.1, you can access it as mysql-server.easynet.net etc.
Now the second and albeit complex part of your question, how to do available and lazy replication.
This is relatively a bit more complex than the previous step. But, what actually happens is that you have to choose a scheme of replication. Basically what you are looking for here is MASTER-MASTER replication since you have a possibility of changes happening at both the MySQL servers. Thus the updates need to be bi-directional, that's what this scheme of replication does. How to do it? Well, I am providing the links which I've found easier to follow:
Master-Master Replication
Step-by-step MySQL Master Replication
I hope that would ease your plight and answer your question!
Cheers!
Sure, you can
You need to setup both MySQL servers as Master and Slave at the same time.
Configure the online server as Master, and the localhost server as slave, and once replication is OK.
Configure the localhost as Master and the online server as slave.
I already did that on two servers.
About the dynamic IP on the local host, simply you can use any dynamic IP service like: no-ip, and use the dns name instead of the IP.
Here's a post i've written (in french, but you can get the configuration snippets from it) for setting up a MASTER-MASTER replication with a load balancer (mysql proxy) for balancing SQL queries between both nodes.
I am currently planing a web application and I want to plan it to eventually run on a cluster later.
The cluster would be made of a php web cluster and a mysql cluster and a standalone storage unit (maybe a cluster of it I really don't know how that works :s)
I want to know if the code will be different than when php and mysql are on the same machine and what would be different?
The fact that the web and database servers are on different physical machines wouldn't change your code at all. The only place you'd need to change code is where you connect to the database - replacing the localhost reference with the IP address or hostname of the database server.
A clustered web server may need a different approach for storing sessions. If you got multiple webservers behind a load balancer, consequitive requests from the same session may end up on different servers. You should store the session data in a different place, like a central memcache.
Apart from a few of those issues, you should be fine regarding the web server.
As far as I know, MySQL and clustering are no friends. Although I wasn't really involved in the process, I know there has been a lot of trouble to get two database servers run together in our environment and even now they are not really clustered. They syncronize, but only one is actively used while the other is a fallback server.
I have a local intranet application which runs off a basic WAMP server in our offices. Every morning, one of our team members manually syncs our internal mysql db with our external mysql db (where our online enrollments occur). If a change is made during the day on the intranet application, it is not reflected on the external db until the following day.
I am wondering if it is possible to (essentially) tunnel to an external mysql connection from say a wamp or xampp server from within our offices and work in 'real-time'.
Anybody had any luck or advice?
Yes
Replication enables data from one MySQL database server (the master) to be replicated to one or more MySQL database servers (the slaves). Replication is asynchronous - slaves need not to connected permanently to receive updates from the master. This means that updates can occur over long-distance connections and even over temporary or intermittent connections such as a dial-up service. Depending on the configuration, you can replicate all databases, selected databases, or even selected tables within a database.
If you use the external server directly, performance is likely to suffer. A Gigabit LAN might be a thousand times faster than your Internet connection - particularly the upload speed of an ADSL connection.
Just make your internal application use the database from the external one. You may need to add permission to the external server to allow connections from your internal server IP, but otherwise this is just like having a webserver and sperate db server that need to access each other.
Can't really tell you how to do this here - it all depends on your specific configuration, something that I would thing is a little complicated (and too specialized) to figure out on SO.
This is quite odd, but I have a script that was until now calling queries on a db that existed only on another server, and is now on my new server with a different name. However, the "host" was always localhost. The user connected to the non-existent DB on localhost, and somehow connected to the existing database instead?
Can someone please explain to me how everything is working properly even though it most certainly should not be? There is only one database currently.
Thanks for explaining, I'm confused.
As I said, just a guess, but if the database user only has access to the correct database, it could be that it automatically selects that database.
No known facts here, just what I think could be involved (which is why I originally posted this as a comment rather than solution).
First you connect to the MySQL server, then the database selection happens. If the database you are trying to select does not exist, the default database for this user remains selected. If only one database is accessible for a user, this database will be selected.
When you say another server? Do you mean another WAMP installation? Or an entirely different computer/operating system.
the "host" was always localhost.
That's the only reason I ask, because perhaps you still have the previous mysql server installed and the "New" one made home on a different non-default port.
If it was always localhost then the db was on that system. Localhost refers to the ip address 127.0.0.1 which is a non-routable ip address. Since it's a non-routable ip address it won't redirect to another computer unless you do it manually. For instance, under Windows hosts file, you can make localhost another ip address besides 127.0.0.1. That would be the only way for localhost to redirect to another computer
Keep in mind that your PHP code runs on the SERVER, not the client machine, so "localhost" as the host parameter in your mysql_connect call will work as long as the PHP code is executing on the same physical or virtual server as your MySQL db.