Difference between server connection and server instance? - mysql-workbench

I was using MySQL Workbench and I am not able to figure out the difference between the following:
1. Server instance
2. Connection to server
In general I want to know if we can use Open Connection to start querying without creating
a server instance of the connection we are trying to connect. Are these two things independent?

You need one or two connections depending on what you wanna do with your server. For MySQL work (i.e. running queries) you need a MySQL connection. For server work (e.g. shutting the MySQL server down or manage other aspects that require shell access) you need a second connection (which is called a Server Instance).
Beginning with MySQL Workbench 6.0 we merged both connection settings into one interface.

Related

Incremental data from Postgresql

I have a number of identical local postgreSql databases (identical in structure - not data) on several laptops that have intermittant access to internet. Records are being added to each DB daily. So Branch A,B,C each with a local Postgresql database. I would like all records from A,B,C in each table in a cloud Database.Also A,B,C data is separate - there is no overlap - A doesnt change B, or C etc. There are no duplicated unique keys.
NEED: I would like to collect all this data on a cloud based database by adding daily incremental data to a single cloud databse - so I can query the whole consolidated data using SQL and pull reports as needed.
Please can anyone point me in the right direction?
Thanks
It sounds like you want logical replication from each laptop to the cloud server. The problem there might be that contact must be made by the replica to each of the masters, so when your laptops are online, they would need to have predictable IP addresses so that they can be reached.
Maybe the best way around this is with a reverse SSH tunnel. On the central replica, you would tell it to subscribe to a publication hosted on some non-standard port on localhost. With a different port reserved for each laptop. So, for example, 9997, 9998, and 9999.
Then when each laptop has connectivity, it could run something like:
ssh rajb#1centralserver.example.com -R9999:localhost:5432 -f -N -T
This establishes an ssh connection to the central server (requiring a password, or private key, or however you have ssh set up) and sends instructions to the central server that whenever someone connects to port 9999 on the central server it should really send that connection back over ssh tunnel and hook it up to port 5432 (the default postgres server port) of the laptop.
For initially setting things up and debugging, you might want to omit the -f -N -T. That way, in addition to setting up the tunnel, you also get an interactive ssh session you can use for monitoring things.
Once the central service notices the connection is available, it will start downloading changes since the last time it could connect. When there is no connection, you will get a lot of nuisance messages to the log file as it checks each server every ~5 seconds to see if it is available.
From each laptop's perspective, the connection is coming from within, so the replication connection will use whatever authentication is set up or 127.0.0.1 or ::1, not the authentication set up for the actual remote IP.

Postgres terminology: client vs connection

In Postgres, is there a one-to-one relationship between a client and a connection? In other word, is a client always one connection and no client can open more than one connection?
For example, when Postgres says:
org.postgresql.util.PSQLException: FATAL: sorry, too many clients already.
is that equivalent to "too many connections already"?
Also, as far as I understand, Postgres uses one process for each client. So does this mean that each process is used for one connection only?
Refer - https://www.postgresql.org/docs/9.6/static/connect-estab.html
PostgreSQL is implemented using a simple "process per user"
client/server model. In this model there is one client process
connected to exactly one server process. As we do not know ahead of
time how many connections will be made, we have to use a master
process that spawns a new server process every time a connection is
requested.
So yes, one server process serves one connection.
You can have as many connections from a single client (machine, application) as the server can manage. The server can support a given number of connections, whether or not these come from different clients (machine, application) is irrelevant to the server.
The connection is made to the postmaster process that is listening on the port that PG is configured to listen to (5432 by default). When a connection is established (after authentication), the server spawns a process which is used exclusively by a single client. That client can make multiple connections to the same server, for instance to connect to different databases, or the same database using different credentials, etc.

How to get the local port of a jdbc connection?

As far as I know when one establishes multiple Connection objects via JDBC to one database then each connection occupies a separate port on the machine where the Connection is established (they all connect to one port on the server where the DBMS is running).
I tried to extract the port that corresponds to the Connection objects. Unfortunately I did not find any way to do so.
Background: I'm doing performance analysis where I setup multiple clients which issue queries on the db. I'm logging the execution time of queries on the database server. In the resulting log I have - among others - information about the connection who initiated the query e.g. localhost.localdomain:44760 I hope it is possible to use this information to map each query to the client or more precisely the Connection object who initiated the query (which is my ultimate goal and serves analysis purposes).
Just run this select through the JDBC connection:
select inet_client_port()
More functions like that are in the manual:
http://www.postgresql.org/docs/current/static/functions-info.html

Accessing an external phpmyadmin on same network

I have a webshop running on a windows 2008 R2 server that can be accessed on a client PC in the same network.
It's working fine, but now I need to get the database from another windows 2008 server instead of running it on the same machine.
I've already installed WAMP on the new server, imported the database into phpmyadmin and opened port 80 for the firewall. In my connection file for the webshop I've changed the HOST to "192.168.0.17:80" (IP adress of the DB server).
I can still connect to the shop and use anything that doesn't use a database, but when I do need the database it loads for a while and it shows me a timeout error.
Pinging to the database from the Webhost server works.
Am I missing something?
Edit:
I can now access PHPMyAdmin from the Webserver through "192.168.0.17/phpmyadmin".
What would I have to enter in the PHP file to connect it to the database?
If you have phpMyAdmin and the webserver running on 192.168.0.17, and the database on, say, 192.168.0.20, then two things need to happen to allow phpMyAdmin to access the database.
MySQL needs to allow users to connect from other machines. By default, this usually is permitted; I'm not particularly sure what changes WAMP might make. If you've created users with host 'localhost', they won't work and you'll need to increase their permissions by modifying the host or creating a new similar user. The usual disclaimers apply about backing up first.
phpMyAdmin needs to be configured to look at the new MySQL server instead of localhost. Open up config.inc.php and edit or change the $cfg['Servers'][$i]['host']... line to read $cfg['Servers'][$i]['host'] = '192.168.0.20';
Once you've done that, you can open up the phpMyAdmin on your webserver and it should now attempt to connect to the other server that now has your MySQL server installed.
I've already installed WAMP on the new server, imported the database
into phpmyadmin and opened port 80 for the firewall. In my connection
file for the webshop I've changed the HOST to "192.168.0.17:80" (IP
adress of the DB server).
I'm not sure what this means. Your web application (what I presume you mean by "webshop") does need to know where the new database is, but port 80 is for web traffic, not MySQL connections (which are port 3306 by default).
One more little note:
In the title you mention "an external phpmyadmin", but in the case of networking as you describe "external" generally means "outside the local network" (which in turn generally means "anywhere on the internet"); I think you mean another machine on the same network which would be internal to your network.
Edit
I realized I'm more confused about your question than I thought, because you wrote
Edit: I can now access PHPMyAdmin from the Webserver through
"192.168.0.17/phpmyadmin".
Which doesn't make sense. I thought you have two servers, the webserver (which runs your web application and phpMyAdmin) and the database server. I am starting to suspect the webserver is actually 192.168.0.17, in which case you've correctly configured your phpMyAdmin to access the new MySQL server, so all you should have to do is update your web application to the proper IP address (without a port!); simply matching what you have in phpMyAdmin's config.inc.php. So instead of 192.168.17:80 as the host in your web application, you want the same hostname or IP address that phpMyAdmin is using to connect to. You can find that on the main page as well under the "Database server" section.

Sql Server Times Out Twice - Connects on 3rd Attempt

I have a WinForms application installed on multiple PCs in an office, and a SQL Server 2012 Express database on the server to which the client application connects.
Each machine fails to connect on the first two attempts giving an error -
Timeout Expired: The timeout period elapsed prior to the completion of the operation or the server is not responding.
However, it always works on the 3rd attempt on all machines!
The server is SBS 2008, the machines are running Windows 7.
The issue was I had used a Named Instanced on SQL Server which by default uses dynamic ports. Hence each connection attempt used a different Port, and each time I was asking the server administrator to allow additional ports. The successful log ins where simply because the dynamic port chosen just so happened to be one previously allowed.
The answer was to use SQL Server Configuration Manager to remove the dynamic port setting and specify a single port to use for all connection attempts, and ensure firewalls etc had an exception for that particular port.