- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change collation to utf8_bin in a single line?
You need to use ALTER command to change collation to utf8_bin. The syntax is as follows:
ALTER TABLE yourTableName COLLATE utf8_general_ci;
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table CollateDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Age int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.98 sec)
Check the DDL of the table. The syntax is as follows:
SHOW CREATE TABLE yourTableName;
Let us now check the DDL of our table:
mysql> show create table CollateDemo;
The following is the output:
+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | CollateDemo | CREATE TABLE `collatedemo` (`Id` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(20) DEFAULT NULL, `Age` int(11) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci | +-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
Now you can change the collation using ALTER command. The query is as follows:
mysql> alter table CollateDemo collate utf8_general_ci; Query OK, 0 rows affected (0.39 sec) Records: 0 Duplicates: 0 Warnings: 0
Now let us check the DDL of the table:
mysql> show create table CollateDemo;
The following is the output:
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | CollateDemo | CREATE TABLE `collatedemo` (`Id` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, `Age` int(11) DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8 | +-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to insert a single line break in HTML?
- How to Transpose a matrix in Single line in Python?
- MySQL query to discover current default database collation (via command line client)?
- How to make MySQL display results in a single line?
- How to write single line comment in Java?
- How to write single-line comments in C#?
- How to change line color in EditText
- How to write a single line in text file using Python?
- How to provide multiple statements on a single line in Python?
- How to plot a single line in Matplotlib that continuously changes color?
- How to add a single data point in an Excel line chart?
- Convert the column to a case-sensitive collation in MySQL?
- How to change the color of a line using radiobuttons in Matplotlib?
- How to change the line color in a Seaborn linear regression jointplot?
- How to convert an MySQL database characterset and collation to UTF-8?

Advertisements