MySQL utf8mb4, Errors when saving Emojis
<p>I try to save names from users from a service in my MySQL database. Those names can contain emojis like  (just for examples)</p>

<p>After searching a little bit I found this <a href="https://stackoverflow.com/questions/7814293/how-to-insert-utf-8-mb4-characteremoji-in-ios5-in-mysql">stackoverflow</a> linking to this <a href="https://mathiasbynens.be/notes/mysql-utf8mb4#utf8-to-utf8mb4" rel="noreferrer">tutorial</a>. I followed the steps and it looks like everything is configured properly.</p>

<p>I have a Database (charset and collation set to utf8mb4 (_unicode_ci)), a Table called TestTable, also configured this way, as well as a "Text" column, configured this way (VARCHAR(191) utf8mb4_unicode_ci). </p>

<p>When I try to save emojis I get an error:</p>

<pre><code>Example of error for shortcake ():
    Warning: #1300 Invalid utf8 character string: 'F09F8D'
    Warning: #1366 Incorrect string value: '\xF0\x9F\x8D\xB0' for column 'Text' at row 1
</code></pre>

<p>The only Emoji that I was able to save properly was the sun ☀️</p>

<p>Though I didn't try all of them to be honest. </p>

<p>Is there something I'm missing in the configuration?</p>

<p><strong>Please note:</strong> All tests of saving didn't involve a client side. I use phpmyadmin to manually change the values and save the data. So the proper configuration of the client side is something that I will take care of <strong>after</strong> the server properly saves emojis. </p>

<p><strong>Another Sidenote</strong>: Currently, when saving emojis I either get the error like above, or get no error and the data of <code>Username </code> will be stored as <code>Username ????</code>. Error or no error depends on the way I save. When creating/saving via SQL Statement I save with question marks, when editing inline I save with question marks, when editing using the edit button I get the error.</p>

<p>thank you</p>

<p><strong>EDIT 1:</strong>
Alright so I think I found out the problem, but not the solution.
It looks like the Database specific variables didn't change properly.</p>

<p>When I'm logged in as root on my server and read out the variables (global):<br>
Query used: <code>SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';</code></p>

<pre><code>+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | utf8mb4            |
| character_set_connection | utf8mb4            |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | utf8mb4            |
| character_set_server     | utf8mb4            |
| character_set_system     | utf8               |
| collation_connection     | utf8mb4_unicode_ci |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+
10 rows in set (0.00 sec)
</code></pre>

<p>For my Database (in phpmyadmin, the same query) it looks like the following:</p>

<pre><code>+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | utf8               |
| character_set_connection | utf8mb4            |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | utf8               |
| character_set_server     | utf8               |
| character_set_system     | utf8               |
| collation_connection     | utf8mb4_unicode_ci |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+
</code></pre>

<p>How can I adjust these settings on the specific database?
Also even though I have the first shown settings as default, when creating a new database I get the second one as settings.</p>

<p><strong>Edit 2:</strong></p>

<p>Here is my <code>my.cnf</code> file:</p>

<pre><code>[client]
port=3306
socket=/var/run/mysqld/mysqld.sock
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld_safe]
socket=/var/run/mysqld/mysqld.sock

[mysqld]
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/run/mysqld/mysqld.sock
port=3306
basedir=/usr
datadir=/var/lib/mysql
tmpdir=/tmp
lc-messages-dir=/usr/share/mysql
log_error=/var/log/mysql/error.log
max_connections=200
max_user_connections=30
wait_timeout=30
interactive_timeout=50
long_query_time=5
innodb_file_per_table
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

!includedir /etc/mysql/conf.d/
</code></pre>