Importing records from PostgreSQL to MySQL - mysql

Was wondering if anyone had any insight or recommended tools for exporting the records from a PostgreSQL database and importing them into a MySQL database. I believe the table structure is 100% identical.
Thoughts? Thanks!

The command
pg_dump --data-only --column-inserts <database_name>
will generate SQL-standard-compliant INSERT statements with all column names listed and one VALUES clause per INSERT. This is the most portable way of moving data from PostgreSQL to any other SQL database.

Check out SquirrelSQL, it can pump data from one database brand into another via the DBCopy plugin. When the table structures are really identical it works quite well.

There is a ruby app called Taps that will do it. I've used it before with great success:
http://adam.heroku.com/past/2009/2/11/taps_for_easy_database_transfers/

Related

Is there any way join tables of MySql and PostgreSQL?

I have a table in MySql in one server and a table in PostgreSQL in another server.
I want use use JOIN operation with those tables.
Is there any way to join the columns?
If not, is there any way to print the rows in same order?
Please help!!
Use mysql_fdw to define the MySQL table as a foreign table in PostgreSQL. Then you can join it with the PostgreSQL table in PostgreSQL.
You can use Materialize to achieve this.
Here is a sample demo project that you can run to see this in action:
You can find the code for the demo project and how to run it on GitHub here:
https://github.com/bobbyiliev/materialize-tutorials/tree/main/mz-join-mysql-and-postgresql
Hope this reference helps.
Yes, it is possible to work with multiple databases at the same time but you're looking in the wrong place. psycopg2 is just a library that simplifies accessing and manipulating data coming out of PostgreSQL but it doesn't go far beyond what you can do with psql. What you're looking to do you can solve on the database level by using Foreign Data Wrappers.
This does become more complicated in your schema definition but brings remote tables from host some.other.server database remote_db to appear as though they live on localhost in database local_db....
More:
https://dba.stackexchange.com/a/120682/197899

MySQL Replace table from another table

I have 2 active database connections, I need to replace a number of tables from 'connection1' with that of connection2. The structures may, or may not be same, (depending if we make changes to the connection1 table.
I would assume I should do a complete table dump and replace keys where neccesary, but I really have no idea how to do this :)
Any help?
Have a look at Schema and Data sync tools in dbForge Studio for MySQL. It will help you to compare two databases on different servers, map tables and fields, generate and run synchronization script.
I ended up using the build in system command in PHP and mysqldump to first dump the data (export) to a file, then used system() again with mysql to import it into the new table and replace the old one.
Works like a charm :)

Pulling Data from MySql and dropping it into SQL

I was wondering if anybody had any advice or references that explain how to pull data from MySQL and drop it into SQLSever! Any input would be greatly appreciated!! Thanks!
You can add MySQL as a "linked server"
http://forums.mysql.com/read.php?60,123221,123221
Once you did that you can reference the MySQL tables, views, etc with their fully qualified name in regular SQL Server queries
I could not tell if you wanted to access a MySQL database because you were migrating to SQL server, or if you wanted to access a MySQL database on an ongoing basis. I am answering as if you want to migrate, because you already have an excellent answer on accessing MySQL from SQL Server.
If you want to migrate, mysqldump is one way to go. Its format is easily parsed.
You can also write the results of any MySQL table -- and SQL Server for that matter -- to .csv format. .csv format is nearly a universal transfer format for data.

Combine several mssql database to one mysql with php

We are handling a data aggregation project by having several microsoft sql server databases combining to one mysql database. all mssql database have the same schema.
The requirements are :
each mssql database can be imported to mysql independently
before being able to import each record to mysql we need to validates each records with a specific createrias via php.
each imported mssql database can be rollbacked. It means even it already imported to mysql, all the mssql database can be removed from the mysql.
we would still like to know where does each record imported to the mysql come from what mssql database.
All import process will be done with PHP .
we have difficulty in many aspects. we don't know what is the best approach to solve our problem.
your help will be highly appreciated.
ps: each mssql database has around 60 tables and each table can have a few hundred thousands .
Don't use PHP as a database administration utility. Any time you build a quick PHP script to transfer records directly from one database to another, you're going to cause yourself a world of hurt when that script becomes required for production operation.
You have a number of problems that you need solved:
You have multiple MSSQL databases with similar if not identical tables.
You have a single MySQL database that you want to merge the data into.
The imported data must be altered in a specific way before being merged.
You want to prevent all duplicate records in your import.
You want to know what database each record originally came from.
The solution?
Analyze the source MSSQL databases and create a merge strategy for them.
Create a database structure on the MySQL database that fits the merge strategy in #1, including all the new key constraints (like unique and foreign keys) required for the consolidation.
At this point you have two options left:
Dump the data from each of the source databases into raw data using your RDBMS administration utility of choice. Alter that data to fit your merge strategy and constraints. Document this, and then merge all of the data into your new database structure.
Use a tool like opendbcopy to map columns from one database to another and run a mass import.
Hope this helps.

postgreSQL to MySQL converter

I have a table in a postgreSQL database that I would like to convert into a MySQL table. What would be the easiest way to do this? Any tools to do this? Remember, I am not converting the whole database to MySQL... I am just taking a table from that postgreSQL and convert it to MySQL table
You can use pg_dump to create a SQL dump from a single table and use this dump as input for mysql. Take a look at the option --data-only when you already have the tablestructure in your MySQL database and --column-inserts to create straight forward INSERT statements.
An ETL tool like SSIS, Pentaho, Talend or several others will do the trick. Most support a wide variety of data sources and destinations.