Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transfer old 3.23.49 MySQL database to 5.0.51 MySQL database - Encoding in ANSI and UTF-8

I want to transfer a 3.23.49 MySQL database to a 5.0.51 MySQL database. Now I have exported the SQL file and I'm ready for import. I looked in the sql-file and Notepad++ shows me that the files is encoded in ANSI. I looked in the values and some of them are in ANSI and some of them are in UTF-8. What is the best way to proceed?

  1. Should I change the encoding within Notepad++?
  2. Should I use ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8;?
  3. Should I use iconv?
  4. Do I have to look through each table and make the necessary changes?
  5. Whate are the settings for the import? MYSQL323 compatibility mode and encoding latin1?
  6. Do I have to be aware of something if the php-scripts are using another encoding?

Thank you for your hints!

like image 716
testing Avatar asked Feb 22 '23 09:02

testing


2 Answers

If the problem is to import a utf8-encoded mysql dump, the solution is usually to add --default-character-set=utf8 to mysql options:

mysql --default-character-set=utf8 -Ddbname -uuser -p < dump.sql

UPD1: In case the dump file is corrupted, I would try to export the database once again table by table so that the dump would result in a correct utf8 encoded file.

like image 92
newtover Avatar answered Feb 24 '23 22:02

newtover


I have converted a MySQL 4.0 database (which also had no notion of character encoding yet) to MySQL 5.0 four years ago, so BTDT.

But first of all, there is no "ANSI" character encoding; that is a misconception and a misnomer that has caught on from the early versions of Windows (there are ANSI escape sequences, but they have nothing to do with character encoding). You are most certainly looking at Windows‑1252-encoded text. You should convert that text to UTF‑8 as then you have the best chance of keeping all used characters intact (UTF‑8 is a Unicode encoding, and Unicode contains all characters that can be encoded with Windows-125x, but at different code points).

I had used both the iconv and recode programs (on the Debian GNU/Linux system that the MySQL server ran on) to convert Windows‑1252-encoded text of a MySQL export (created by phpMyAdmin) to UTF‑8. Use whatever program or combination of programs works best for you.

As to your questions:

  1. You can try, but it might not work. In particular, you might have trouble opening a large database dump with Notepad++ or another text editor.
  2. Depends. ALTER TABLE … CONVERT TO … does more than just converting encodings.
  3. See the paragraph above.
  4. Yes. You should set the character encoding of every table and every text field that you are importing data into, to utf8 (use whatever utf8_… collation fits your purpose or data best). ALTER TABLE … CONVERT TO … does that. (But see 2.)
  5. I don't think MYSQL323 matters here, as your export would contain only CREATE, INSERT and ALTER statements. But check the manual first (the "?" icon next to the setting in phpMyAdmin). latin1 means "Windows-1252" in MySQL 5.0, so that might work and you must skip the manual conversion of the import then.
  6. I don't think so; PHP is not yet Unicode-aware. What matters is how the data is processed by the PHP script. Usually the Content-Type header field for your generated text resources using that data should end with ; charset=UTF-8.

On an additional note, you should not be using MySQL 5.0.x anymore. The current stable version is MySQL 5.5.18. "Per the MySQL Support Lifecycle policy, active support for MySQL 5.0 ended on December 31, 2009. MySQL 5.0 is now in the Extended support phase." MySQL 5.0.0 Alpha having been released on 2003-12-22, Extended Support is expected to end 8 full years after that, on 2011‑12‑31 (this year).

like image 21
PointedEars Avatar answered Feb 24 '23 22:02

PointedEars