Modify MySQL character set with Navicat for MySQL

更新时间:
复制 MD 格式

This topic describes how to use Navicat for MySQL to modify the character set encoding of MySQL databases for Web Hosting and Simple Application Server instances.

Prerequisites

Ensure that Navicat for MySQL is installed.

Note

Download Navicat for MySQL from the Navicat official website.

Procedure

  1. Obtain the database information.
    1. Web Hosting management pageLog in to the Web Hosting console.
    2. ActionsManageFind the Web Hosting instance and click in the column.
    3. Database InformationIn the left-side navigation pane, click .
    4. On the Database Information page, view your database connection details.
      Note If you forget the database password, reset it. For more information, see Reset the password of a Web Hosting database.
      数据库
  2. Start Navicat for MySQL.

  3. From the menu bar, select Connection > MySQL.

  4. In the MySQL - New Connection dialog box, enter the database information and click OK.

    Parameter

    Description

    Connection Name

    Enter a name for the connection.

    Host

    Enter the database endpoint.

    Port

    Enter the connection port for the database. The default port for MySQL is 3306.

    User Name

    Enter the username for the database.

    Password

    Enter the password for the database.

  5. In the left-side navigation pane, right-click the name of the connected database and select Command Line Interface.

  6. In the command input box of the Command-line Interface dialog box that appears, run the following command to view the database character set encoding information.

    show variables like "char%"

    The command returns the following character set encoding details.

    mysql> show variables like "char%";
    +-------------------------+-------------------------------------------+
    | Variable_name           | Value                                     |
    +-------------------------+-------------------------------------------+
    | character_set_client    | utf8                                      |
    | character_set_connection| utf8                                      |
    | character_set_database  | gbk                                       |
    | character_set_filesystem| binary                                    |
    | character_set_results   | utf8                                      |
    | character_set_server    | gbk                                       |
    | character_set_system    | utf8                                      |
    | character_sets_dir      | /usr/local/mysql/share/mysql/charsets/     |
    +-------------------------+-------------------------------------------+
    8 rows in set
  7. In the command input field, run the following command to modify the character set encoding of the database.

    alter database <database_name> character set <charset_name>

Results

The following example shows the output after changing the database character set encoding to utf8.

mysql> alter database xxx character set utf8;
Query OK, 1 row affected
mysql> show variables like "char%";
+-------------------------------+----------------------------------------+
| Variable_name                 | Value                                  |
+-------------------------------+----------------------------------------+
| character_set_client          | utf8                                   |
| character_set_connection      | utf8                                   |
| character_set_database        | utf8                                   |
| character_set_filesystem      | binary                                 |
| character_set_results         | utf8                                   |
| character_set_server          | gbk                                    |
| character_set_system          | utf8                                   |
| character_sets_dir            | /usr/local/mysql/share/mysql/charsets/  |
+-------------------------------+----------------------------------------+
8 rows in set