Home >Database >Mysql Tutorial >How Can I Store and Retrieve Unicode Data in MySQL?

How Can I Store and Retrieve Unicode Data in MySQL?

Susan Sarandon
Susan SarandonOriginal
2024-11-23 21:50:12562browse

How Can I Store and Retrieve Unicode Data in MySQL?

Storing Unicode in MySQL

Despite the absence of an explicit "nvarchar" type, MySQL supports Unicode storage through its character sets. To store Unicode data, you must select a suitable UTF-8 character set for your table.

Steps to Store Unicode in MySQL:

  1. Create a Database and Table:
CREATE DATABASE UnicodeDB;
USE UnicodeDB;
CREATE TABLE UnicodeTable (
  UnicodeColumn TEXT
);
  1. Specify UTF-8 Character Set for Table:
ALTER TABLE UnicodeTable CONVERT TO CHARACTER SET utf8;

After this conversion, the "UnicodeColumn" will be able to store Unicode characters.

Note:

  • MySQL 6 will introduce support for UTF-16.
  • Using "text" data type alone will not enable Unicode storage. It must be paired with UTF-8 character set conversion.
  • To retrieve Unicode data from a MySQL database, use the utf8_decode() function to convert it back to its original form (if needed).

The above is the detailed content of How Can I Store and Retrieve Unicode Data in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn