Determining the current character encoding set
To determine which character encoding set a MySQL database or table is currently using:- Log in to your account using SSH.
-
At the command line, type the following command, replacing username with your username:
- At the Enter Password prompt, type your password. When you type the correct password, the mysql> prompt appears.
-
To display the current character encoding set for a particular database, type the following command at the mysql> prompt. Replace dbname with the database name:
-
To display the current character encoding set for a particular table in a database, type the following command at the mysql> prompt. Replace dbname with the database name, and tablename with the name of the table:
-
To exit the mysql program, type
\qat the mysql> prompt.
Converting the character encoding set to UTF-8
To convert the character encoding set to UTF-8:- Log in to your account using SSH.
-
Create a text file named .my.cnf. To do this, you can use a text editor such as Vim or Nano. This procedure shows how to use Nano. At the command line, type the following command:
-
Add the following lines to the file, replacing username with your username and password with your password (make sure the password is enclosed in quotation marks):
-
When the edits are complete, press Ctrl+X, type
yto save the file, and then press Enter. -
To change the character set encoding to UTF-8 for all of the tables in the specified database, type the following command at the command line. Replace dbname with the database name:
-
After the command finishes, type the following command to start the mysql program:
-
To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace dbname with the database name:
-
To exit the mysql program, type
\qat the mysql> prompt. -
To delete the .my.cnf file, type the following command at the command line:
- To verify that the character set encoding is now set to UTF-8, follow the steps in the Determining the current character encoding set procedure above.