I have a MySQLdump generated by PHPMyAdmin, and I need to import it into a Postgresql database, but I dont know if it's even possible. I've seen people recommending pgloader but seens a little confusing on how to do it. Also I'm on windows if its relevant at all.
I only need the tables, so I'm not concerned about the data in the old or in the new database.
It's not that big too, only 84 tables. But big enough for me to write it.
Thank you!
You can use pgloader.
You need to install it, and then run a simple lisp script (script.lisp) with the following 3 lines:
/* content of the script.lisp */
LOAD DATABASE
FROM mysql://dbuser#localhost/dbname
INTO postgresql://dbuser#localhost/dbname;
/*run this in the terminal*/
pgloader script.lisp
And after that, your PostgreSQL DB will have all of the information that you had in your MySQL DB.
There are a lot of resources to do this. None of them are simple.
pgloader which you mentioned is among the many tools listed on this page: https://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL#MySQL
MySQLdump is supposed to have an option --compatible=postgres but don't rely on that. It makes some changes to its output, but not enough to be fully compatible with PostgreSQL syntax.
Another option is to dump tables to CSV files with mysqldump --tables instead of dumping to SQL format. Then you can bulk-load the CSV files one by one with the COPY statement in PostgreSQL.
If your MySQL database contains views or stored routines (procedures, functions, triggers, or events), then in general those can't be converted by any tool. The PostgreSQL language for stored routines is too different from MySQL. You must just start over and code routines in PostgreSQL that do equivalent logic, but coded in a way more idiomatic for PostgreSQL.
Related
I'm migrating a large(approx. 10GB) MySQL database(InnoDB engine).
I've figured out the migration part. Export -> mysqldump, Import -> mysql.
However, I'm trying to figure out the optimum way to validate if the migrated data is correct. I thought of the following approaches but they don't completely work for me.
One approach could have been using CHECKSUM TABLE. However, I can't use it since the target database would have data continuously written to it(from other sources) even during migration.
Another approach could have been using the combination of MD5(), GROUP_CONCAT, and CONCAT. However, that also won't work for me as some of the columns contain large JSON data.
So, what would be the best way to validate that the migrated data is correct?
Thanks.
How about this?
Do SELECT ... INTO OUTFILE from each old and new table, writing them into .csv files. Then run diff(1) between the files, eyeball the results, and convince yourself that the new tables' rows are an appropriate superset of the old tables'.
These flat files are modest in size compared to a whole database and diff is fast enough to be practical.
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 :)
Hello is there any method to transfer the table layout and data from a Postgres database to MySQL automatic?
I have to migrate the scheme anda data to MYSQL
The easiest would probably be to export the database (schema & data) as SQL using Postgres' pg_dump utility, then import the resulting SQL file into MySql.
It's possible that there will be some incompatibilities in the intermediate SQL, but you can almost assuredly take care of these with a find/replace in your favorite text editor.
It is possible to do using the "Data Transfer" feature of Navicat Premium. It will not preserve foreign keys though, but the data transfers correctly with the two databases incompatibility issues resolved.
if i have 2 diff database(A&B),now i want to migrate all data (not only the tables, but also include the procedure) from A to B,is there any way to solve this?
There are a few utilities that come packaged with mysql. Have you looked at mysqldump? It allows you to create a backup of a database which you can recreate elsewhere.
As Zach pointed out, mysqldump can handle this. If you would rather a GUI, you could also try Toad. It has a schema compare option that can show you the differences between the two databases and let you choose which tables and routines you wish to migrate.
I would like to write a script that supports the following workflow.
given: a defined set of queries (select statements with table joins) that return sets of data from a single MySQL database
create: a SQLite database that contains the information (tables, data) required to returned the same results to the same set of queries sent in step 1.
Outside of select, delete, and update, I am relatively unfamiliar with SQL, so I would appreciate specific command line or SQL syntax... anything required beyond installing SQLite.
This's an half answer but can be usefull also for other kind of DB.
mysqldump has the option "compatible" to control the standard compliance of the sql dumped.
From the "mysqldump --help" execution:
--compatible=name Change the dump to be compatible with a given mode. By
default tables are dumped in a format optimized for
MySQL. Legal modes are: ansi, mysql323, mysql40,
postgresql, oracle, mssql, db2, maxdb, no_key_options,
no_table_options, no_field_options. One can use several
modes separated by commas. Note: Requires MySQL server
version 4.1.0 or higher. This option is ignored with
earlier server versions.
Abe, this doesn't answer your question but might help you get started. You can export the database using mysqldump with --complete-insert (since sqlite does not support multi-row / compound inserts), then use sqlite3_exec() to import the dump to SQLite