INSERT INTO ... in MariaDB in Ubuntu under Windows WSL2 results in corrupted data in some columns

Viewed 46

I am migrating a MariaDB database into a Linux docker container.

I am using mariadb:latest in Ubuntu 20 LTS via Windows 10 WSL2 via VSCode Remote WSL.

I have copied the sql dump into the container and imported it into the InnoDB database which has DEFAULT CHARACTER SET utf8. It does not report any errors:

> source /test.sql

That file does this (actual data truncated for this post):

  USE `mydb`;
  DROP TABLE IF EXISTS `opsitemtest`;

  CREATE TABLE `opsitemtest` (
    `opId` int(11) NOT NULL AUTO_INCREMENT,
    `opKey` varchar(50) DEFAULT NULL,
    `opName` varchar(200) DEFAULT NULL,
    `opDetails` longtext,
    PRIMARY KEY (`opId`),
    KEY `token` (`opKey`)
  ) ENGINE=InnoDB AUTO_INCREMENT=4784 DEFAULT CHARSET=latin1;

  insert  into `opsitemtest`(`opId`,`opKey`,`opName`,`opDetails`) values
  (4773,'8vlte0755dj','VTools addin for MSAccess','<p>There is a super helpful ...'),
  (4774,'8vttlcr2fTA','BAS OLD QB','<ol>\n<li><a href=\"https://www.anz.com/inetbank/bankmain.asp\" ...'),
  (4783,'9c7id5rmxGK','STP - Single Touch Payrol','<h1>Gather data</h1>\n<ol style=\"list-style-type: decimal;\"> ...');

If I source a subset of 12 records of the table in question all the columns are correctly populated.

If I source the full set of data for the same table ( 4700 rows ) where everything else is the same, many of the opDetails long text fields have a length showing in sqlYog but no data is visible. If I run a SELECT on that column there are no errors but some of the opDetails fields are "empty" (meaning: you can't see any data), and when I serialize that field, the opDetails column of some records (not all) has

"opDetails" : "\u0000\u0000\u0000\u0000\u0000\u0000\",

( and many more \u0000 ).

The opDetails field contains HTML fragments. I am guessing it is something to do with that content and possibly the CHARSET, although that doesn't explain why the error shows up only when there are a large number of rows imported. The same row imported via a set of 12 rows works correctly.

The same test of the full set of data on a Windows box with MariaDB running on that host (ie no Ubuntu or WSL etc) all works perfectly.

I tried setting the table charset to utf8 to match the database default but that had no effect. I assume it is some kind of Windows WSL issue but I am running the source command on the container all within the Ubuntu host.

The MariaDB data folder is mapped using a volume, again all inside the Ubuntu container:

volumes:
      - ../flowt-docker-volumes/mariadb-data:/var/lib/mysql

Can anyone offer any suggestions while I go through and try manually removing content until it works? I am really in the dark here.

EDIT: I just ran the same import process on a Mac to a MariaDB container on the OSX host to check whether it was actually related to Windows WSL etc and the OSX database has the same issue. So maybe it is a MariaDB docker issue?

EDIT 2: It looks like it has nothing to do with the actual content of opDetails. For a given row that is showing the symptoms, whether or not the data gets imported correctly seems to depend on how many rows I am importing! For a small number of rows, all is well. For a large number there is missing data, but always the same rows and opDetails field. I will try importing in small chunks but overall the table isn't THAT big!

EDIT 3: I tried a docker-compose without a volume and imported the data directly into the MariaDB container. Same problem. I was wondering whether it was a file system incompatibility or some kind of speed issue. Yes, grasping at straws!

Thanks, Murray

1 Answers

OK. I got it working. :-)

One piece of info I neglected to mention, and it might not be relevant anyway, is that I was importing from an sql dump from 10.1.48-MariaDB-0ubuntu0.18.04.1 because I was migrating a legacy app.

So, with my docker-compose:

Version Result
mysql:latest data imported correctly
mariadb:latest failed as per this issue
mariadb:mariadb:10.7.4 failed as per this issue
mariadb:mariadb:10.7 failed as per this issue
mariadb:10.6 data imported correctly
mariadb:10.5 data imported correctly
mariadb:10.2 data imported correctly

Important: remember to completely remove the external volume mount folder content between tests!

So, now I am not sure whether the issue was some kind of sql incompatibility that I need to be aware of, or whether it is a bug that was introduced between v10.6 and 10.7. Therefore I have not logged a bug report. If others with more expertise think this is a bug, I am happy to make a report.

For now I am happy to use 10.6 so I can progress the migration- the deadline is looming!

So, this is sort of "solved".

Thanks for all your help. If I discover anything further I will post back here. Murray

Related