skip to Main Content

Let’s say that I want to send the following SQL query to the MySQL server:

SELECT * FROM students;

Which character set will be used to encode the above statement, and which character set will be used to encode the response from the MySQL server? and can you change this character set?

2

Answers


  1. Look at system variables of your MySQL server and definition of database and tables:

    mysql> SHOW VARIABLES like '%char%';
    
    mysql> show create database <your_database_name>;
    
    mysql> show create table <your table, like "students">;
    

    By default tables have database charset.

    MySQL automatically changes the encoding of strings when entering data into the table and when fetching data from the table. It uses data from system variables, such as character_set_client for this.

    Login or Signup to reply.
  2. The question is not quite right. You need to specify the character set encoding in two places: The bytes on the client and the bytes on the server.

    Client encoding

    Best: Establish the in/out character set via connection parameters. There you specify the encoding of the client.

    Second best is SET NAMES utf8mb4; right after connecting (assuming you want utf8mb4).

    Server encoding

    The charset on each column (in the database) comes from the column definition. If missing, then the default comes from the table definition. Run SHOW CREATE TABLE.

    If client and server are not the same, MySQL will transcode when INSERTing and when SELECTing.

    If you have specific symptoms, see Trouble with UTF-8 characters; what I see is not what I stored

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search