- MySQL Basics
- MySQL - Home
- MySQL - Introduction
- MySQL - Features
- MySQL - Versions
- MySQL - Variables
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Node.js Syntax
- MySQL - Java Syntax
- MySQL - Python Syntax
- MySQL - Connection
- MySQL - Workbench
- MySQL Databases
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Show Database
- MySQL - Copy Database
- MySQL - Database Export
- MySQL - Database Import
- MySQL - Database Info
- MySQL Users
- MySQL - Create Users
- MySQL - Drop Users
- MySQL - Show Users
- MySQL - Change Password
- MySQL - Grant Privileges
- MySQL - Show Privileges
- MySQL - Revoke Privileges
- MySQL - Lock User Account
- MySQL - Unlock User Account
- MySQL Tables
- MySQL - Create Tables
- MySQL - Show Tables
- MySQL - Alter Tables
- MySQL - Rename Tables
- MySQL - Clone Tables
- MySQL - Truncate Tables
- MySQL - Temporary Tables
- MySQL - Repair Tables
- MySQL - Describe Tables
- MySQL - Add/Delete Columns
- MySQL - Show Columns
- MySQL - Rename Columns
- MySQL - Table Locking
- MySQL - Drop Tables
- MySQL - Derived Tables
- MySQL Queries
- MySQL - Queries
- MySQL - Constraints
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Replace Query
- MySQL - Insert Ignore
- MySQL - Insert on Duplicate Key Update
- MySQL - Insert Into Select
- MySQL Indexes
- MySQL - Indexes
- MySQL - Create Index
- MySQL - Drop Index
- MySQL - Show Indexes
- MySQL - Unique Index
- MySQL - Clustered Index
- MySQL - Non-Clustered Index
- MySQL Operators and Clauses
- MySQL - Where Clause
- MySQL - Limit Clause
- MySQL - Distinct Clause
- MySQL - Order By Clause
- MySQL - Group By Clause
- MySQL - Having Clause
- MySQL - AND Operator
- MySQL - OR Operator
- MySQL - Like Operator
- MySQL - IN Operator
- MySQL - ANY Operator
- MySQL - EXISTS Operator
- MySQL - NOT Operator
- MySQL - NOT EQUAL Operator
- MySQL - IS NULL Operator
- MySQL - IS NOT NULL Operator
- MySQL - Between Operator
- MySQL - UNION Operator
- MySQL - UNION vs UNION ALL
- MySQL - MINUS Operator
- MySQL - INTERSECT Operator
- MySQL - INTERVAL Operator
- MySQL Joins
- MySQL - Using Joins
- MySQL - Inner Join
- MySQL - Left Join
- MySQL - Right Join
- MySQL - Cross Join
- MySQL - Full Join
- MySQL - Self Join
- MySQL - Delete Join
- MySQL - Update Join
- MySQL - Union vs Join
- MySQL Keys
- MySQL - Unique Key
- MySQL - Primary Key
- MySQL - Foreign Key
- MySQL - Composite Key
- MySQL - Alternate Key
- MySQL Triggers
- MySQL - Triggers
- MySQL - Create Trigger
- MySQL - Show Trigger
- MySQL - Drop Trigger
- MySQL - Before Insert Trigger
- MySQL - After Insert Trigger
- MySQL - Before Update Trigger
- MySQL - After Update Trigger
- MySQL - Before Delete Trigger
- MySQL - After Delete Trigger
- MySQL Data Types
- MySQL - Data Types
- MySQL - VARCHAR
- MySQL - BOOLEAN
- MySQL - ENUM
- MySQL - DECIMAL
- MySQL - INT
- MySQL - FLOAT
- MySQL - BIT
- MySQL - TINYINT
- MySQL - BLOB
- MySQL - SET
- MySQL Regular Expressions
- MySQL - Regular Expressions
- MySQL - RLIKE Operator
- MySQL - NOT LIKE Operator
- MySQL - NOT REGEXP Operator
- MySQL - regexp_instr() Function
- MySQL - regexp_like() Function
- MySQL - regexp_replace() Function
- MySQL - regexp_substr() Function
- MySQL Fulltext Search
- MySQL - Fulltext Search
- MySQL - Natural Language Fulltext Search
- MySQL - Boolean Fulltext Search
- MySQL - Query Expansion Fulltext Search
- MySQL - ngram Fulltext Parser
- MySQL Functions & Operators
- MySQL - Date and Time Functions
- MySQL - Arithmetic Operators
- MySQL - Numeric Functions
- MySQL - String Functions
- MySQL - Aggregate Functions
- MySQL Misc Concepts
- MySQL - NULL Values
- MySQL - Transactions
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - SubQuery
- MySQL - Comments
- MySQL - Check Constraints
- MySQL - Storage Engines
- MySQL - Export Table into CSV File
- MySQL - Import CSV File into Database
- MySQL - UUID
- MySQL - Common Table Expressions
- MySQL - On Delete Cascade
- MySQL - Upsert
- MySQL - Horizontal Partitioning
- MySQL - Vertical Partitioning
- MySQL - Cursor
- MySQL - Stored Functions
- MySQL - Signal
- MySQL - Resignal
- MySQL - Character Set
- MySQL - Collation
- MySQL - Wildcards
- MySQL - Alias
- MySQL - ROLLUP
- MySQL - Today Date
- MySQL - Literals
- MySQL - Stored Procedure
- MySQL - Explain
- MySQL - JSON
- MySQL - Standard Deviation
- MySQL - Find Duplicate Records
- MySQL - Delete Duplicate Records
- MySQL - Select Random Records
- MySQL - Show Processlist
- MySQL - Change Column Type
- MySQL - Reset Auto-Increment
- MySQL - Coalesce() Function
MySQL - SET CHARACTER SET Statement
A character set of MySQL is the set of legal characters that are allowed in a string. MySQL provides several character-sets you can see the list of all the available character sets using the SHOW CHARACTER SET statement.
SHOW CHARACTER SET\G;
Output
The above mysql query produces the following output −
*********** 1. row ********** Charset: armscii8 Description: ARMSCII-8 Armenian Default collation: armscii8_general_ci Maxlen: 1 ********** 2. row ********** Charset: ascii Description: US ASCII Default collation: ascii_general_ci Maxlen: 1 ********** 3. row ********** Charset: big5 Description: Big5 Traditional Chinese Default collation: big5_chinese_ci Maxlen: 2 ********** 4. row ********** Charset: binary Description: Binary pseudo charset Default collation: binary Maxlen: 1 ********** 5. row ********** Charset: cp1250 Description: Windows Central European Default collation: cp1250_general_ci Maxlen: 1 ********** 6. row ********** Charset: cp1251 Description: Windows Cyrillic Default collation: cp1251_general_ci Maxlen: 1 ********** 7. row ********** Charset: cp1256 Description: Windows Arabic Default collation: cp1256_general_ci Maxlen: 1 ********** 8. row ********** Charset: cp1257 Description: Windows Baltic Default collation: cp1257_general_ci Maxlen: 1 ********** 9. row ********** Charset: cp850 Description: DOS West European Default collation: cp850_general_ci Maxlen: 1 ********** 10. row ********** Charset: cp852 Description: DOS Central European Default collation: cp852_general_ci Maxlen: 1 ********** 11. row ********** Charset: cp866 Description: DOS Russian Default collation: cp866_general_ci Maxlen: 1 ********** 12. row ********** Charset: cp932 Description: SJIS for Windows Japanese Default collation: cp932_japanese_ci Maxlen: 2 ********** 13. row ********** Charset: dec8 Description: DEC West European Default collation: dec8_swedish_ci Maxlen: 1 ********** 14. row ********** Charset: eucjpms Description: UJIS for Windows Japanese Default collation: eucjpms_japanese_ci Maxlen: 3 ********** 15. row ********** Charset: euckr Description: EUC-KR Korean Default collation: euckr_korean_ci Maxlen: 2 ********** 16. row ********** Charset: gb18030 Description: China National Standard GB18030 Default collation: gb18030_chinese_ci Maxlen: 4 ********** 17. row ********** Charset: gb2312 Description: GB2312 Simplified Chinese Default collation: gb2312_chinese_ci Maxlen: 2 ********** 18. row ********** Charset: gbk Description: GBK Simplified Chinese Default collation: gbk_chinese_ci Maxlen: 2 ********** 19. row ********** Charset: geostd8 Description: GEOSTD8 Georgian Default collation: geostd8_general_ci Maxlen: 1 ********** 20. row ********** Charset: greek Description: ISO 8859-7 Greek Default collation: greek_general_ci Maxlen: 1 ********** 21. row ********** Charset: hebrew Description: ISO 8859-8 Hebrew Default collation: hebrew_general_ci Maxlen: 1 ********** 22. row ********** Charset: hp8 Description: HP West European Default collation: hp8_english_ci Maxlen: 1 ********** 23. row ********** Charset: keybcs2 Description: DOS Kamenicky Czech-Slovak Default collation: keybcs2_general_ci Maxlen: 1 ********** 24. row ********** Charset: koi8r Description: KOI8-R Relcom Russian Default collation: koi8r_general_ci Maxlen: 1 ********** 25. row ********** Charset: koi8u Description: KOI8-U Ukrainian Default collation: koi8u_general_ci Maxlen: 1 ********** 26. row ********** Charset: latin1 Description: cp1252 West European Default collation: latin1_swedish_ci Maxlen: 1 ********** 27. row ********** Charset: latin2 Description: ISO 8859-2 Central European Default collation: latin2_general_ci Maxlen: 1 ********** 28. row ********** Charset: latin5 Description: ISO 8859-9 Turkish Default collation: latin5_turkish_ci Maxlen: 1 ********** 29. row ********** Charset: latin7 Description: ISO 8859-13 Baltic Default collation: latin7_general_ci Maxlen: 1 ********** 30. row ********** Charset: macce Description: Mac Central European Default collation: macce_general_ci Maxlen: 1 ********** 31. row ********** Charset: macroman Description: Mac West European Default collation: macroman_general_ci Maxlen: 1 ********** 32. row ********** Charset: sjis Description: Shift-JIS Japanese Default collation: sjis_japanese_ci Maxlen: 2 ********** 33. row ********** Charset: swe7 Description: 7bit Swedish Default collation: swe7_swedish_ci Maxlen: 1 ********** 34. row ********** Charset: tis620 Description: TIS620 Thai Default collation: tis620_thai_ci Maxlen: 1 ********** 35. row ********** Charset: ucs2 Description: UCS-2 Unicode Default collation: ucs2_general_ci Maxlen: 2 ********** 36. row ********** Charset: ujis Description: EUC-JP Japanese Default collation: ujis_japanese_ci Maxlen: 3 ********** 37. row ********** Charset: utf16 Description: UTF-16 Unicode Default collation: utf16_general_ci Maxlen: 4 ********** 38. row ********** Charset: utf16le Description: UTF-16LE Unicode Default collation: utf16le_general_ci Maxlen: 4 ********** 39. row ********** Charset: utf32 Description: UTF-32 Unicode Default collation: utf32_general_ci Maxlen: 4 ********** 40. row ********** Charset: utf8mb3 Description: UTF-8 Unicode Default collation: utf8mb3_general_ci Maxlen: 3 ********** 41. row ********** Charset: utf8mb4 Description: UTF-8 Unicode Default collation: utf8mb4_0900_ai_ci Maxlen: 4
You can get the name of the default character set using the following query −
SELECT default_character_set_name FROM information_schema.SCHEMATA S WHERE schema_name = "test";
Output
After executing the above mysql query, it generates the output shown below −
DEFAULT_CHARACTER_SET_NAME |
---|
utf8mb4 |
The SET CHARACTER SET Statement
The SET CHARACTER SET Statement of MySQL 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
Following query sets the character set to macroman −
SET CHARACTER SET macroman;
Verification
You can verify the current value of the character_set_client and character_set_results variables using the show variables like statement as shown below −
show variables like "character_set_client";
Output
The above query produces the following output −
Variable_name | Value |
---|---|
character_set_client | macroman |
show variables like "character_set_results";
Output
Following is the output of the above mysql query −
Variable_name | Value |
---|---|
character_set_results | macroman |
The DEFAULT value
You can set the character set mapping to the default one of the databases using the DEFAULT as value as shown below −
SET CHARACTER SET DEFAULT;
Since the default character set is utf8mb4, the values of the character_set_client and character_set_results variables are set to it. You can verify these values as shown below −
show variables like "character_set_results";
Output
After executing the above query, it produces the following output −
Variable_name | Value |
---|---|
character_set_results | utf8mb4 |
show variables like "character_set_client";
Output
The above mysql query will generate the output shown below −
Variable_name | Value |
---|---|
character_set_client | utf8mb4 |
SET CHARSET statement
You can also use the CHARSET keyword instead of CHARACTER SET as shown below −
SET CHARSET latin7;
Verification
Let us verify the current value of the character_set_client or, character_set_results variables using the show variables like statement as shown below −
show variables like "character_set_client";
Output
After executing the above query, it will produce the following output −
Variable_name | Value |
---|---|
character_set_client | latin7 |
To Continue Learning Please Login
Login with Google