MS SQL 2017 to MySql 8 migration with MySql Workbench - mysql

I've got a problem during migration. To migrate data between SQL Server 2017 and MySQL I use MySQL workbench (version 8.0.12). When script for new tables generation is completed I can find that there are many places where int is set to default value of '', for example:
CREATE TABLE IF NOT EXISTS `myname`.`Table1` (
`version` INT NOT NULL DEFAULT '',
...
)
And this, of course, is not working in next steps. Since I've got 'version' column in each table, is there any way that I can change this globally?
I know that I can go to each table and change it manually but it will be a lot of clicking...

Related

Error when importing virtual column from MySQL to MariaDB

I'm moving a database from MySQL to MariaDB, and testing export/import. One issue that's come up consistent is when a table has virtual columns. SHOW CREATE TABLE in MySQL returns this:
CREATE TABLE `table1` (
`colA` varchar(50) NOT NULL,
`colB' varchar(50) NOT NULL,
'vir1` GENERATED ALWAYS AS (concat_ws(' ', `colA`, `colB`)) VIRTUAL NOT NULL,
`colC` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
MariaDB then reports an error when importing it:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL,
`colC` varchar(50) DEFAULT NULL
The problem appears to be in the "VIRTUAL NOT NULL" part of the virtual column definition. If I edit the import sql file by hand, to this:
CREATE TABLE `table1` (
`colA` varchar(50) NOT NULL,
`colB' varchar(50) NOT NULL,
'vir1` GENERATED ALWAYS AS (concat_ws(' ', `colA`, `colB`)) VIRTUAL,
`colC` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
then it imports just fine, so I guess MariaDB doesn't like being told whether a virtual field is allowed to be null or not (which seems logical, since it wouldn't know whether the inputs are null or not), but the exported MySQL file always has either VIRTUAL NULL or VIRTUAL NOT NULL as part of the exported table definitions.
Is there a way to avoid this? I could grep through the exported file to s&r those definitions, but that seems kludgey and at risk of running into other issues later if it's a compatibility issue with a known solution.
The syntax you show works in MySQL, I just tested with MySQL 5.7 and it does not cause an error.
The MariaDB syntax is not compatible. This has been reported as a bug: https://jira.mariadb.org/browse/MDEV-10964
You could vote for that bug, or even contribute a patch to resolve it.
The bottom line is that MariaDB forked from MySQL in 2010, and the two products have been growing further and further apart ever since then. They should no longer be considered compatible.
Just like if you were to migrate from a MySQL database to PostgreSQL or Microsoft SQL Server, there will be some edits needed to make MySQL syntax work on different brands of RDBMS.
The problem is that null / not null is a part of mysql's definition of generated columns, therefore mysqldump exports these properties as part of dumping the table structures. This is the right thing to do as mysqldump is designed to work with mysql and not with mariadb.
You should use a proper ETL tool for migrating data between different database products, even if those pruducts are as closely related to each other as mysql and mariadb are.

MySQL autoincrement column have diffrent behaviour with different databases

I have one working project in php and mysql.
In which I am using one column syntax for all my auto increment columns like below -
CREATE TABLE `mytable` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`sometext` int(11) NOT NULL
)
And for inserting records in this table in my whole proect I am using below syntax -
INSERT INTO mytable(ID,sometext)
VALUES(0,'Sometext')
And this is working fine.
But when I copied same DB and project and this code stopped working
So I changed my insert with below
INSERT INTO mytable( sometext)
VALUES( 'Sometext')
But this is very weird... In previous project old syntax is working fine but for new I have to make code change in 100 of places.
Can somebody tell me whats wrong with new MYSQL DB that it stopped supporting old syntax.
The difference is probably that your new database servers has the configuration option sql_mode=NO_AUTO_VALUE_ON_ZERO. Therefore only a NULL will cause an auto-increment to be generated.
Read https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html for full explanation of how sql modes affect your database server.
To avoid having to make code changes, you can change the server option.

mysqldump output is not a valid Oracle "create table" format

I'm trying to move data from a MySQL database (5.6.32-78) to an Oracle Database (11g). Using mysqldump, the output causes a "missing right parenthesis" error when creating a table in oracle. ie...
mysqldump output:
CREATE TABLE "table1" (
"ID" int(11) NOT NULL,
"column1" int(11) NOT NULL DEFAULT '0',
"column2" varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY ("ID")
);
Oracle is expecting the following (the order of NOT NULL and DEFAULT switched):
CREATE TABLE "table1" (
"ID" int(11) NOT NULL,
"column1" int(11) DEFAULT '0' NOT NULL,
"column2" varchar(255) DEFAULT '' NOT NULL,
PRIMARY KEY ("ID")
);
Is there an option I'm missing to correct this? I have a couple hundred tables to move and do not want to "reinvent the wheel" by writing procedure to get the correct output.
(--compatible=oracle does not make any difference).
Thanks.
Doug
I'll try to make the question more specific.
I am trying to migrate a MySQL to Oracle database and tried using mysqldump and various options, but it does not generate an Oracle usable output. I can't use Oracle's SQL Developer because it requires connecting to both the MySQL database (internet) and Oracle database (inside of a "no internet access" firewall) at the same time. Is anyone aware of a way to create an Oracle friendly export of a MySQL database?
The order of NOT NULL and DEFAULT is only one problem you'll face. There are many differences between MySQL and Oracle that cannot be fixed with mysqldump options.
http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_compatible says:
This option does not guarantee compatibility with other servers. It only enables those SQL mode values that are currently available for making dump output more compatible. For example, --compatible=oracle does not map data types to Oracle types or use Oracle comment syntax.
So you would have to do some hand-editing of your dump file before importing it to Oracle.
You're better off using Oracle SQL Developer to migrate your MySQL database to Oracle. You can find a step-by-step guide with videos here: http://www.oracle.com/technetwork/database/migration/index.html
Note the steps for MySQL can be found by clicking the link "and others..." below the list of other commercial RDBMS products. Here's a direct link: http://www.oracle.com/technetwork/database/migration/mysql-093223.html

mysql error when backing up a database that has views

When I back up a database (Structure and Data)
Options Checked:
CREATE DATABASE before copying
Add AUTO_INCREMENT value
it fails if the database has a view in it. I do not get this error backing up any other databases.
Here is Error message. I do not know what #1050 is in the MYSQL documentation:
SQL query: Edit Edit
CREATE TABLE vw_MediaOutlets-lk-ClientForContact (
fk_client_id INT( 11 ) , id INT( 11 ) , outlet_name TEXT,
outlet_subjects TEXT, email TEXT, circulation TEXT,
contact_title TEXT, city TEXT, state TEXT );
MySQL said: Documentation
1050 - Table 'vw_MediaOutlets-lk-ClientForContact' already exists
And then the result is an empty copied database.
I am using phpMyAdmin version 4.0.5
and mysql version 5.1.70-cll
on a shared hosted server
Any thoughts?
Thanks!

Problem using HSQLDB Transfer Tool with MySQL

I am trying to use the HSQLDB transfer tool to migrate a Database from MySQL. The tool is able to get the tables from the source MySQL database, however when I "start the transfer" I get the error,as follows and tables are not created in the target HSQLDB database.
org.hsqldb.util.DataAccessPointException: Unexpected token: PRIMARY in statement
[CREATE TABLE INST(INST_ID BIGINT NOT NULL ,INST_NAME VARCHAR NOT NULL ,INST_CO
DE VARCHAR NOT NULL ,PARENT BIGINT,OPEN_TIME TIMESTAMP,CLOSE_TIME TIMESTAMP,INST
_STATUS VARCHAR NOT NULL ,SCD_LICENSE CHAR(1) NOT NULL ,ADDRESS_LINE1 VARCHAR,AD
DRESS_LINE2 VARCHAR,CITY_ID BIGINT NOT NULL ,CASH_LIMIT BIGINT,DESCRIPTION VARCH
AR,INST_TYPE VARCHAR NOT NULL ,LAST_UPDATED_BY BIGINT NOT NULL ,LAST_UPDATED_DAT
E TIMESTAMP NOT NULL , CONSTRAINT PRIMARY]
Any idea how I could overcome this?
My main intention is to convert MySQL SQL into HSQLDB equivalenst, I guess there uses to be a tool to do this before MySQL workbench.
The documentation says that the Transfer Tool has not been developed for several years. I think you need to create a tool by your self, which translates a MYSQL Object DDL (Create Table, Create Procedure, etc) to a HSQL Object DDL (Which is basically SQL standards 92, 1999, 2003 and 2008).
I'm currently searching for one my self.
If you find one, please update this post?