Home > Database > Mysql Tutorial > How to Properly Store Arabic Text in a MySQL Database?

How to Properly Store Arabic Text in a MySQL Database?

Linda Hamilton
Release: 2024-12-13 00:57:10
Original
520 people have browsed it

How to Properly Store Arabic Text in a MySQL Database?

How to Save Arabic Data in MySQL Database

A common issue encountered when storing Arabic data in a MySQL database is the appearance of "???" marks instead of Arabic text. To rectify this, a series of steps must be taken.

Check Character Set and Collation

Ensure that the database, table, and columns are using the UTF-8 character set. Use the following queries to verify:

-- Database
SELECT default_character_set_name FROM information_schema.SCHEMATA S WHERE schema_name = "your_database_name";
-- Table
SELECT CCSA.character_set_name FROM information_schema.`TABLES` T, information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA WHERE CCSA.collation_name = T.table_collation AND T.table_schema = "your_database_name" AND T.table_name = "your_table_name";
-- Column
SELECT character_set_name FROM information_schema.`COLUMNS` C WHERE table_schema = "your_database_name" AND table_name = "your_table_name" AND column_name = "your_column_name";
Copy after login

Set UTF-8 for Database, Table, and Column

If any component is not set to UTF-8, follow these steps:

  1. For Database: Run ALTER DATABASE your_database_name CHARACTER SET = utf8 COLLATE = utf8_general_ci;
  2. For Table: Run ALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
  3. For Column: Run ALTER TABLE your_table_name MODIFY your_column_name VARCHAR(255) CHARACTER SET utf8;

Manually Insert Arabic Data

After setting UTF-8, insert Arabic data directly into the MySQL client using Arabic key sequences. For example, to insert the Arabic text "كتگوری" into the category_name column, use the following query:

INSERT INTO `categories` (`category_name`) VALUES ('كتگوری');
Copy after login

Additional Tips

  • Use the SQLYog tool to set UTF-8 for tables if available.
  • Check the character encoding of the Arabic text, as it may be different from the default encoding on your system.

The above is the detailed content of How to Properly Store Arabic Text in a MySQL Database?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template