
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Set column charset in MySQL?
Set column charset using character SET command. The syntax is as follows −
ALTER TABLE yourTableName MODIFY youColumName type CHARACTER SET anyCharcaterSetName;
You can use character set name utf8 or something elsE. To set column charset, let us first create a table. The query to create a table is as follows −
mysql> create table setCharsetDemo −> ( −> FirstName varchar(60) −> ); Query OK, 0 rows affected (2.09 sec)
Now you can check the current column character set with the help of show command. The query is as follows −
mysql> show create table setCharsetDemo;
The following is the output −
+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | setCharsetDemo | CREATE TABLE `setcharsetdemo` (`FirstName` varchar(60) COLLATE utf8mb4_unicode_ci DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci | +----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
Now you can look at the above sample output. The default charset is utf8mb4. Let us set the charset to be other than utf8mb4.
We will set the character set to utf8. The query is as follows −
mysql> alter table setCharsetDemo modify FirstName varchar(60) CHARACTER SET utf8; Query OK, 0 rows affected, 1 warning (2.81 sec) Records: 0 Duplicates: 0 Warnings: 1
Let us check the character set have been changed or not. The query is as follows −
mysql> show create table setCharsetDemo;
The following output displays that we have successfully updated the charset −
+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | setCharsetDemo | CREATE TABLE `setcharsetdemo` (`FirstName` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci | +----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- Determine what a MySQL DB’s charset is set to
- Set ENUM in MySQL for column values
- Set existing column as Primary Key in MySQL?
- Set Blank spaces in column names with MySQL?
- Set new delay time in a MySQL column
- Set conditions while adding column values in MySQL?
- HTML Charset
- How to change the default charset of a MySQL table?
- Increment column value ‘ADD’ with MySQL SET clause
- Set NOT NULL attribute to an existing column in MySQL
- Set default value to a JSON type column in MySQL?
- HTML charset Attribute
- HTML charset Attribute
- How to set all values in a single column MySQL Query?
- HTML accept-charset Attribute

Advertisements