Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert Hindi language in Mysql

Tags:

mysql

hindi

I changed the charset set but does not work

CREATE TABLE `tbl_hindi` (
  `data` varchar(1000) character set utf8 collate utf8_bin default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `tbl_hindi` VALUES ('कंप्यूटर');
like image 222
Sanjay Dutt Avatar asked Jul 02 '12 11:07

Sanjay Dutt


People also ask

How to insert hindi text in sql database?

Note: You need to have the N prefix to make SQL Server consider the Text as NVARCHAR. INSERT INTO Languages VALUES('English', 'World is beautiful. ') INSERT INTO Languages VALUES('Hindi', N'दुनियासुंदरहै।

How to store hindi in database?

1) Choose utf8 character set and utf8_general_ci collation. 2) Whenever you want to save and retrieve the data you need to set the characterset as follows. //To set the char set mysql_set_charset('utf8'); //To select hindi data mysql_query("SELECT * FROM ...."); // To insert hindi data mysql_query("INSERT INTO ....");


2 Answers

The charset of the database needs to be utf8_unicode_ci.

Try creating a new database, as well as a new table.

CREATE DATABASE hindi_test
    CHARACTER SET utf8
    COLLATE utf8_unicode_ci;

USE hindi_test;

CREATE TABLE `hindi` (
    `data` varchar(200) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `hindi` (`data`) VALUES
    ('कंप्यूटर');

This works on my install. If it doesn't work for you, something might be wrong with your server settings.

like image 153
Jørgen R Avatar answered Oct 25 '22 22:10

Jørgen R


You do not need database change, all you need is to alter table column.

ALTER TABLE `YOUR TABLE` CHANGE `data ` `data ` VARCHAR(1000) 
CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL; 

This change works fine and very feasible.

like image 38
anwerj Avatar answered Oct 26 '22 00:10

anwerj