periklis
periklis

Reputation: 10192

Convert text to blob in mysql

I want to convert a "text" field to "blob" in mysql 5. Will the data be affected in any way if I simply run

alter table <table> change <col> <col> blob;

I tried it and it worked with no problems, I was just wondering if there's something I may be missing or should take special care of.

Upvotes: 4

Views: 18500

Answers (3)

Arun Pratap Singh
Arun Pratap Singh

Reputation: 3646

ALTER TABLE myTableName MODIFY COLUMN columnName BLOB;

Yup you shouldn't face any problem except sorting.

As mysql will convert "text" to binary data when changed to "blob" and vice versa.

you can simply get

String str = resultSet.getString(columnIndex) 
// or 
byte[] byteArr = resultSet.setBytes(columnIndex).
String str = new String(byteArr );

Upvotes: 1

Jaydee
Jaydee

Reputation: 4158

You shouldn't have any problems. The main differences between blob and text are in the way they are sorted (eg numeric v lexicographic). They hold the same size of data and there doesn't seem to be any fiddling (eg with carriage returns / newlines).

Useful page in the manual

http://dev.mysql.com/doc/refman/5.0/en/blob.html

Upvotes: 4

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146390

You can simply make a new dump and compare it against your backup. Use WinMerge, KDiff3 or your tool of choice.

Upvotes: 0

Related Questions