Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect string value: '\xF0\x9F\x92\x8F\x0A#...for column in mysql?

I am new to MySQL. I have a column which stores Unicode character in MySQL table.

I have a code which gets the posts from the twitter,facebook etc. and insert the text/symbol 'as is' into the table.

CREATE TABLE `tbl_unicode` (
  `_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `first_name` varchar(45) NOT NULL,
  `uninoce_Column` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`_id`)

) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8;


/* This query WONT work due to SYMBOL:💏   */
INSERT INTO `tbl_unicode`
  (`_id`,
  `first_name`,
  `uninoce_Column`)
VALUES
  (2,
  'rakesh',
  '最高の休日💏
#京都#宮津#天の橋立#');


/* This query WORKS FINE */
INSERT INTO `tbl_unicode`
  (`_id`,
  `first_name`,
  `uninoce_Column`)
VALUES
  (1,
  'shekhar',
  '最高の休日
#京都#宮津#天の橋立#');
enter code here

Live Demo in SQLFiddle

So, which datatype or configuration should i do to make it work.

Any suggestions?

like image 824
SHEKHAR SHETE Avatar asked Dec 12 '25 02:12

SHEKHAR SHETE


1 Answers

CHARACTER SET utf8

MySQL's utf8 charset is not UTF-8. That would be too easy! Instead, it's a limited subset of UTF-8 where only code points up to U+00FFFF, which can be stored in three UTF-8 bytes, are supported. 💏 is U+01F48F, so it doesn't fit in the table's charset.

The real UTF-8 character set is known in MySQL (5.5 and later) as utf8mb4.

like image 143
bobince Avatar answered Dec 14 '25 15:12

bobince



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!