How to Insert Arabic Characters in MySQL

How to Insert Arabic Characters in MySQL thumbnail
Insert Arabic characters with the UTF-8 character set.

Modifying your MySQL database to use the UTF-8 character set is important if you want to store Arabic characters in your database. UTF-8 is an encoding for the Unicode character set, which includes the Arabic alphabet. Before inserting Arabic text you have to make sure the MySQL database, tables and columns are using the UTF-8 character set. Modifying the database is done with the "ALTER" keyword. The application you are inserting from also needs to use UTF-8.

Instructions

    • 1

      Log in to the MySQL database. Using a terminal this is done with the command:

      mysql -u username -p password

    • 2

      Alter the MySQL database, tables and any text columns that you are going to insert Arabic characters into with the UTF-8 character set and collate using the commands:

      ALTER my_database

      CHARACTER SET utf8 COLLATE utf8_general_ci

      ALTER my_table t1

      CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci

      ALTER my_table t1 MODIFY

      my_column VARCHAR(100)

      CHARACTER SET utf8 COLLATE utf8_general_ci

    • 3

      Check the character set configuration of the application you're inserting data with to make sure it's using UTF-8. For example, if you are using PHP and HTML, add the PHP header "header('Content-Type: text/html; charset=utf-8' );" at the top of your file, include the HTML meta-tag "<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>" in the HTML <head> section and call the "mysql_set_charset('utf8',$my_db_link)" function after connecting to the database.

    • 4

      Insert Arabic characters with the following MySQL command:

      INSERT INTO my_table (my_column) VALUES ('my_string')

      Replace "my_string" with your Arabic string.

Related Searches:

References

  • Photo Credit Duncan Smith/Photodisc/Getty Images

Comments

Related Ads

Featured