How i get data from another database in another server? [duplicate] - mysql

This question already has answers here:
How to update a table automatically as another table is updated on different mysql server?
(2 answers)
Closed 6 years ago.
I get 2 database, "db1" and "db2", in 2 different servers, "server1" and "server2".
The 2 databases have the same structure, and I would like connect one database with another. I want to create a trigger which insert data in table "user" of "db1" when I insert data in table "user" of "db2".
Can I do that?
Thanks
PS: At first I don't care if trigger is before, after ... because what I want know is how to connect two databases.

This is not a job for triggers but for replication.
Replication enables data from one MySQL database server (the master)
to be copied to one or more MySQL database servers (the slaves)
If you really wanted to you could have changes in server1 reflected in server2 and vice verce! Though setting it up for one direction is simpler and more usual.

Related

Copy all data from one database to the other MySQL - MariaDB [duplicate]

This question already has answers here:
Mysql Copy Database from server to server in single command
(3 answers)
Closed 1 year ago.
So I would like to make a test playground for my website where I don't alter with the original production data, and therefore I want to make a copy of all my data, and put it into another database. But how can I do this the right way?
I have a database with a lot of tables called testreporting4, and I want to make a copy of all the data/structure into the database called testreportingdebug
From testreporting4 to testreportingdebug
My database size is around 3.1GB at the moment (don't know if that changes anything)
I think the easiest way is the export the database and then import it. More information regarding exporting/importing MariaDB: https://www.digitalocean.com/community/tutorials/how-to-import-and-export-databases-in-mysql-or-mariadb

In MySQL, can I ask it to completely clone a database to a new database in the same instance? [duplicate]

This question already has answers here:
MySQL: Cloning a MySQL database on the same MySql instance
(16 answers)
Closed 2 years ago.
We are wondering if we can run some command in such a way that our prod_addressdb can be cloned along with constraints, table schemas, and then all the data as well.
This would avoid any real data transfer and help us immensely in the short term. Is this even a possibility without doing a mysql dump that transfers it to my slow machine and then import which is way way slow from my machine.
and then later, a point to point like mysqlinstance.prod_addressb -> mysqlstaginginstance.staging_adddressdb would be super super nice as well.
Is there a way to do any of this?
We are in google cloud and the export dumps a file with "create database prod_addressdb" so when we try to import, it fails to go to the staging_addressdb location :(. The exported file is in cloud storage and I don't know of a way to automatically go through and find and replace all the prod_addressdb with staging_addressdb :(. Looking at this problem from many different angles to try to create a pre-production testing location of deploy prod to staging and upgrade and test.
thanks,
Dean
There is no single SQL statement to clone multiple tables.
You can use CREATE TABLE <newschema>.<newtable> LIKE <oldschema>.<oldtable> but this doesn't include foreign keys.
You can use SHOW CREATE TABLE <oldtable> and then execute it in the new schema. That includes foreign keys.
You will find it's easier to load data into the new tables before you create foreign keys. Then run ALTER TABLE to add the foreign keys after you're done copying data.
Then you can copy data from an old table to a new table, one table at a time:
INSERT INTO <newschema>.<newtable> SELECT * FROM <oldschema>.<oldtable>;
Note this locks the data you're reading from the old table while it runs the copy. I'm not sure of the size of your data or how long this would take on your cloud instance. But it does achieve the goal of avoiding data transfer to the client and back to the server.

How to achieve redundancy between 2 tables of different databases?

First of all I'd like to start saying that I've checked these two questions:
Sync 2 tables of different databases - MySQL
How to synchronize two tables of different databases on the same machine (MySql)
But while similar they are not what i need.
I have 2 databases in the same server.
Db1 and Db2
Both databases have the exact copy of a single table called "user":
userid
login
name
lastname
password
level
How can I achieve some sort of redundancy between these two tables in different databases?
If db1.user gets a new record then db2.user has to have that record, if a record is modified then the other one is modified and if deleted the then the other one gets deleted too.
To be more specific, db2.user needs to be a reflection of db1.user using triggers.
EDIT: there is this question: Mysql replication on single server and that is not even remotely close to what i want to do. I updated a little bit at the very end of what i previously posted with how I'd like to achieve this thanks to a suggestion.
As proposed you can use triggers as stated in this standard documentation.
You define AFTER INSERT,AFTER UPDATE and AFTER DELETE triggers on db1.user and within this trigger you have the NEW.object to pass the information into the db2.user table.

Use 1 table in 5 mysql server and connect servers togther

hello this is my mysql table
table_clients
client_id
client_username (UNIQUE)
client_password
now i want to get 5 servers and install mysql on each server and use this table on each 5 servers.
my question is: is there any way that all 5 servers connected to each other (by 1 request) and converted to 1 big server? i mean if there is one user with username (hiworld) in server 2, can not create it this user again in other servers !. (connect all 5 server with same table together and make them 1 big server) .. is it possible?
my queries are too big (2-3 bilion) and i want to share them between 3-4 servers but (make servers united) like when use 1 server )
How to create linked server MySQL
"Cross Linked Servers" a functionality that exists on Ms Sql is the type of thing your looking for.
You would need to do some sort of insert trigger that checked to see if the name existed on the other server.
But this will be slow plus there is a risk of two servers getting the same name at the same time and allowing the insert because when it checked the other name was not already there.
No real good way of doing this. One idea may be to have only one master table for the table_clients. Make it a master to slave relationship. Any time you have to do an insert you insert to the master table/database, then copy that data to the slave instances. But you would still have to cross link the servers for this to work. What you are describing would require waiting on 5 servers to tell if the name has already been used. This way you only have to check on one server.

migrate postgreSQL data to mysql [duplicate]

This question already has answers here:
Migrate database from Postgres to MySQL [closed]
(3 answers)
Closed 8 years ago.
I'm looking to grab a few bits of data from musicbrainz db to use in a mysql based app.
I don't need the entire database, and have been looking at 'migrating' postgreSQL to mysql, which it seems lots of people have difficulty with.
Wouldn't it be simplest to just dump the postgreSQL data into a comma-delimited text file, and then import that into mysql?
I'm just getting started with this, and don't even have postgreSQL installed yet, but trying to look ahead at how I'm going to do it.
You can use COPY (in the psql client) to dump a single table.
Or you can use pg_dump with the -d parameter. This will cause pg_dump to dump INSERT statements, which you can just execute against your MySQL server. You will obviously need to port the schema first - and assuming the datatypes that are used exist in MySQL.
Perhaps you want to dump you Database to a SQL script.