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?
- Should I change the encoding within Notepad++?
- Should I use
ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8;? - Should I use iconv?
- Do I have to look through each table and make the necessary changes?
- Whate are the settings for the import? MYSQL323 compatibility mode and encoding latin1?
- Do I have to be aware of something if the php-scripts are using another encoding?
Thank you for your hints!
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
iconvandrecodeprograms (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:
ALTER TABLE … CONVERT TO …does more than just converting encodings.utf8(use whateverutf8_…collation fits your purpose or data best).ALTER TABLE … CONVERT TO …does that. (But see 2.)MYSQL323matters here, as your export would contain onlyCREATE,INSERTandALTERstatements. But check the manual first (the “?” icon next to the setting in phpMyAdmin).latin1means “Windows-1252” in MySQL 5.0, so that might work and you must skip the manual conversion of the import then.Content-Typeheader 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).