skip to Main Content

Let’s say if I’m making a website where I let people using emojis in their username, and I will have a table for each user to store their info/profiles/etc.., and the name of will be the same as their username.

I have no problem storing emojis or any special character into a table as data.

The character set and collation are both set utf8mb4 for my database, and I also have "CHARSET=utf8mb4" statement in my php mysqli_query function when I create the tables, it worked perfect for all kind of symbols, Chinese Characters, Japanese characters, even when I try to have these special character as part of the table names, no problem.

However, when I try to have emojis as part of the table names, whether I rename or create a table, mysql gives me a “#1300 – Invalid utf8mb4 character string” error.

Is it not possible to have emoji in the table names? If it is possible, how to do it?

2

Answers


  1. Don’t do it and rethink your database design. There are better ways to store usernames than coding them into the table name.

    Login or Signup to reply.
  2. The answer to the question you asked is no, you can’t use emojis in table identifiers, at least not in current versions of MySQL (as of version 8.3).

    mysql> create table `my😊table` ( i int );
    Query OK, 0 rows affected, 1 warning (0.02 sec)
    
    mysql> show warnings;
    +---------+------+-----------------------------------------------------------------------+
    | Level   | Code | Message                                                               |
    +---------+------+-----------------------------------------------------------------------+
    | Warning | 1300 | Cannot convert string 'myxF0x9Fx98x8A...' from utf8mb4 to utf8mb3 |
    +---------+------+-----------------------------------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> show tables;
    +----------------+
    | Tables_in_test |
    +----------------+
    | my?table       |
    +----------------+
    

    https://dev.mysql.com/doc/refman/8.0/en/identifiers.html says:

    Permitted characters in quoted identifiers include the full Unicode Basic Multilingual Plane (BMP), except U+0000

    The BMP is the subset of UTF-8 that corresponds to MySQL’s utf8mb3 character set. The Supplemental Multilingual Plane (SMP) is the full range of UTF-8, which corresponds to MySQL’s utf8mb4 character set.

    Basically, as of MySQL 8.3, the information_schema tables still uses utf8mb3, which only supports the Basic Multilingual Plane. I expect this to change eventually, as they seem to be phasing out utf8mb3 in favor of utf8mb4, but it will be in some future version of MySQL.

    Emojis are in the Supplemental Multilingual Plane.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search