Course
Character Set
MySQL Tutorial
This SQL tutorial is structured for beginners to guide them from the foundational concepts to advanced data manipulation and querying techniques in SQL. By the end of this tutorial, you will have developed a robust understanding of SQL, equipping you with the knowledge to efficiently manage and analyze data across various database systems. This guide sets the stage for your growth into a skilled data professional, ready to tackle complex data challenges and contribute to the field of data analysis and database management.
Character Set
The MySQL Character Set
The MySQL Character set is used to determine the set of permissible characters within a string. It allows for the storage of data in various character encodings. By default, MySQL uses the "utf8mb4" character set.
These character sets provides several functionalities −
- Storage Variety − MySQL allows the storage of strings in various character sets.
- String Comparison − Collations help in comparing strings based on the chosen character set.
- Mixed Character Sets − It is possible to combine strings with different character sets or collations within the same server, database, or table.
- Specifying Character Set and Collation − You can define the character set and collation at different levels of the database structure.
The MySQL Show Character-Set
You can use the MySQL SHOW CHARACTER SET statement to view the list of all the available character sets.
Syntax
Following is the syntax of the SHOW CHARACTER SET statement
SHOW CHARACTER SET [LIKE 'pattern' | WHERE expr]
Example
The following query retrieves a list of available character sets, along with their descriptions, default collations, and maximum lengths in a MySQL database
SHOW CHARACTER SET;
Output
Following is the output obtained
The MySQL Set Character-set
The MySQL SET CHARACTER SET Statement is used to assign a value to the character set attribute. It maps all the strings between the server and the current client with the specified mapping set. This statement changes values of the "character_set_client" and "character_set_results" variables.
Syntax
Following is the syntax of the MySQL SET CHARACTER SET Statement
SET {CHARACTER SET | CHARSET} {'charset_name' | DEFAULT}
Where, 'charset_name' is the name of the character set.
Example
The query given below sets the character set to "macroman"
SET CHARACTER SET macroman;
Output
The output produced is as shown below
Query OK, 0 rows affected (0.10 sec)
Verification
You can verify the character set values using the SHOW VARIABLES LIKE statement as shown below
SHOW VARIABLES LIKE "character_set_client";
Following is the output obtained
Now verifying the current value of the "character_set_results" variable
SHOW VARIABLES LIKE "character_set_results";
The result produced is as shown below