Use mysqldump to export data that is compatible with older versions - mysql

Is it possible to use a newer version of mysqldump to export data that is compatible with older versions of mysql?
Specifically, I am using mysqldump to export data from version 5.5.44 to 5.1.55.
I was getting the error
Unknown collation: 'utf8mb4_unicode_ci'
when trying to import data from the 5.5.44 to the 5.1.55 server
I know in the manual, it says that the compatible option can be used with one of the following names: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, or no_field_options, but I'm not sure if that is what I want in this situation.

If I really wanted a sure-fire solution I would use mysql40 - 5.1 can definitely load a dump from 4.0, MySQL philosophy is backwards compatibility to a fault. However, it is quite likely to work as is - dumps have not changed very much between 5.1 and 5.5.

Related

mysqldump compatible mode postgresql is not working

I need to convert a mysql database to postgres. Just for testing, I installed a local mysql database and created a simple test database with one table. Now I wan't to make a SQL dump with the option --compatible=postgresql:
mysqldump test --compatible=postgresql -uroot > ~/Documents/testdump.sql
But I always get the following error message:
Invalid mode to --compatible: postgresql
I'm using OSX and installed mysql using homebrew
the mysql version is: stable 8.0.12 (bottled)
I also tried it with the Docker-container and the newest version 8.0.12 but it also gives me the same error message. I need the compatible mode so I can use the dump with an python script to convert it to postgresql.
Edit:
I downgraded to 5.7 and it's now working - I'm still wondering why it's not working with the new version.
If you check the documentation for MySQL 8, you will find this:
--compatible=name
Produce output that is more compatible with other database systems or
with older MySQL servers. The only permitted value for this option
is ansi, which has the same meaning as the corresponding option for
setting the server SQL mode.
So setting the value of name to postgresql won't work.
https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html#option_mysqldump_compatible
For 5.7 the following values are possible, which is the reason that a downgrade enabled you to use the desired value:
--compatible=name
Produce output that is more compatible with other database systems or
with older MySQL servers. The value of name can be ansi, mysql323,
mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options,
no_table_options, or no_field_options.

Can mysql 5.7 recognize mysqldump file from 5.1?

we know the supported logical upgrade method is:
5.1-5.5,
5.5-5.6,
5.6-5.7.
In each step, we mysqldump, then we need 3times.
If I mysqldump from 5.1, then install mysql5.7, we need 1 time mysqldump.
Can mysql 5.7 recognize mysqldump file from 5.1?
You should look at the differences that MySQL 5.7 offer compared to the older versions and see if it affects anything but considering how large of a jump it is, I find it hard it would "just work." In short, most likely not. Your best bet is to take your data in MySQL 5.1, upgrade it to 5.7 so your schema inherits all the changes that may have happened, and then make a new mysqldump of that.
Related sources:
https://dba.stackexchange.com/questions/123154/migrating-upgrading-a-mysql-5-1-schema-to-mysql-5-7-schema
Upgrading directly from MySQL 5.0 to 5.7

Downgrade data from MySQL 5.7 to MySQL 5.1

I need to downgrade data from MySQL 5.7 to MySQL 5.1. are there any ways to do in simple steps? (backup and restore )T
There is a solution is step by step like downgrade from 5.7 to 5.6, and then to 5.5.
The Following link says step by step
Make sure you're not using features from 5.7, that are not avaliable in 5.1, for example utf8mb4 encoding (needed for emoji characters)
Then most safe option is to mysql_dump all databases via mysqldump, except for mysql (actually you need mysql.user table, but it's safer to recreate, other settings tables may and most probably will not fit)
Try restoring on staging server first, to see if restored db works the way you expect it to

MySQL migrate data from 5.1 to 5.6 - threats

I do plan to migrate the database from version 5.1 to version 5.6.
I want to do this by using mysqldump:
Export (by mysqldump) data from MySQL DB 5.1 to sql file,
Import (by mysqldump) this sql file that MySQL 5.6 database,
Do not have a complex database that migration can be associated with some risks?
What to look for?
I can not do update database from 5.1 a 5.6, because I can not stop the production base at this point.
Generally speaking it is safe (and supported) to upgrade using mysqldump.
My best suggestion is to use mysqldump from MyQSL 5.6 against the 5.1 server, as newer versions have quite a few fixes to ensure the correct order when dumping foreign keys and other bits and pieces. Your 5.1 version may have these fixes already, but using the newer version won't hurt in any case.
Ensure you run mysql_upgrade after importing the database into 5.6, and then restart the server, as per the MySQL upgrade guide:
http://dev.mysql.com/doc/refman/5.6/en/upgrading.html
Alternatively if you can update in two steps, you can do a in-place binary upgrade by first upgrading to 5.5.x before 5.6.x, ensuring to run mysql_upgrade during both steps.

Import of older MySQL databases (5.6.10) into 5.6.12 generates errors

I created what I thought was a simple sql dump from the older database before installing the latest version, 5.6.12 on Mac OS X Server. Now I'm trying to import the files but they produce all produce endless numbers of syntax errors.
Example of errors:
[ERROR in query 9] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=InnoDB AUTO_INCREMENT=6' at line 8
[ERROR in query 10] Table 'some.table' doesn't exist
Any tips?
Thanks in advance!
You answered your own question:
The problem was: TYPE=InnoDB . As I understand it should be ENGINE=InnoDB . Sequel Pro on Mac (1.0.2) produces an sql dump with "TYPE" by default.
Yes, this is deprecated syntax.
http://dev.mysql.com/doc/refman/5.1/en/create-table.html says:
Note
The older TYPE option was synonymous with ENGINE. TYPE has been deprecated since MySQL 4.0 but is still supported for backward compatibility in MySQL 5.1 (excepting MySQL 5.1.7). Since MySQL 5.1.8, it produces a warning. It is removed in MySQL 5.5. You should not use TYPE in any new applications, and you should immediately begin conversion of existing applications to use ENGINE instead. (See the Release Notes for MySQL 5.1.8.)
So the keyword has been deprecated since 2006, and removed from the product since 2010!
I found this bug already reported here: https://code.google.com/p/sequel-pro/issues/detail?id=1668
The dev's reply is that Sequel Pro uses SHOW CREATE TABLE to export table definitions. If your SQL_MODE = "MYSQL323" or "MYSQL40", then SHOW CREATE TABLE will use the outdated TYPE option instead of the proper ENGINE option. So you can work around the issue by making sure your SQL_MODE is not configured for compatibility with an old version of MySQL.