Home > Database > Mysql Tutorial > How Can I Display MySQL Tables with UTF-8 Characters Correctly?

How Can I Display MySQL Tables with UTF-8 Characters Correctly?

Barbara Streisand
Release: 2024-11-02 08:15:29
Original
999 people have browsed it

How Can I Display MySQL Tables with UTF-8 Characters Correctly?

MySQL Command Line Formatting with UTF8: Preserving Table Layout

Problem:

MySQL command line output for tables containing non-Latin characters becomes distorted when switching to UTF-8 encoding. This can hinder readability.

Short Answer:

Launch the MySQL client with the --default-character-set=utf8 option. Alternatively, set this option in the /etc/mysql/my.cnf file.

Detailed Explanation:

The --default-character-set option forces the character set variables (character_set_client, character_set_connection, and character_set_results) to UTF-8. This ensures that data is formatted properly even when displaying non-Latin characters.

However, if the problem persists, consider the following:

  • Database and Table Character Sets: Ensure that the database, tables, and columns are also set to UTF-8 using the CHARACTER SET and COLLATE attributes.
  • Connection Character Sets: Verify that the MySQL connection's character set variables (character_set_client, character_set_connection, and character_set_results) are all set to UTF-8 using the show variables like '%char%' command.
  • Data Encoding: If data was inserted into a UTF-8 column via a client using a different encoding (e.g., Latin1), the data may appear garbled. Connect to the database using the same charset as the data was inserted or retrieve and rewrite the data with the correct encoding.

Consideration:

Note that MySQL's UTF-8 implementation (utf8) may not fully conform to the UTF-8 standard. If a true and full UTF-8 implementation is required, use the utf8mb4 charset instead.

The above is the detailed content of How Can I Display MySQL Tables with UTF-8 Characters Correctly?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template