I need to change column type from tinyInt(used as bool) to Varchar, without loosing data. I have found many answers on stack-overflow but all of them are written in postgres and I have no idea how to rewrite it in Mysql. Answers for this problem on stack-overflow looks like that:
ALTER TABLE mytabe ALTER mycolumn TYPE VARCHAR(10) USING CASE WHEN mycolumn=0 THEN 'Something' ELSE 'TEST' END;
How would similar logic look like in Mysql?
The syntax you show has no equivalent in MySQL. There's no way to modify values during an ALTER TABLE. An ALTER TABLE in MySQL will only translate values using builtin type casting. That is, an integer will be translated to the string format of that integer value, just it would in a string expression.
For MySQL, here's what you have to do:
Add a new column:
Backfill that column:
If the table has millions of rows, you may have to do this in batches.
Drop the old column and optionally rename the new column to the name of the old one:
Another approach would be to change the column, allowing integers to convert to the string format of the integer values. Then update the strings as you want.
Either way, be sure to test this first on another table before trying it on your real table.