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

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

Related

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.

Rename a database in mysql using linux [duplicate]

This question already has answers here:
How do I rename a MySQL database (change schema name)?
(46 answers)
Closed 3 years ago.
I created a database with the name of old. Now I need to change database name to new.
But,I did not know how to change a name?
I believe that the ability to rename a database has been removed from the spec for security reasons. What you will need to do is create a full dump of the database "old". Then you'll need to create a new database and re-import the data

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

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.

Move data from PostgreSQL to MySQL database [duplicate]

This question already has answers here:
Transfer data from PostgreSQL to MySQL
(2 answers)
Closed 9 years ago.
I have a PostgreSQL database with 50 tables which I need to export then import it in MySQL database. I need to maintain same table fields, data inside tables.
I am using pgAdmin III, tried using the Backup (Plain) feature but couldn't then import data and tables in mysql
I have also tried searching the web on how to do so but failed to locate any useful info so any help is highly appreciated.
Thanks
Take a look at http://www.mysql.com/products/workbench/
It has a Migration Wizard.

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.