How to convert the charset of system schema `mysql` in proper way? - mysql

While upgrading mysql from 5.6 -> 5.7 -> 8.0.23 in step 5.7 -> 8.0.23 I got a recommendation:
The following objects use the utf8mb3 character set. It is recommended to convert them to use utf8mb4 instead, for improved Unicode support.
More Information:
https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html
...
mysql - schema's default character set: utf8
...
So, Is it enough to change the charset of the schema mysql to utf8mb4? Or at first, does it need to convert all the tables of this schema to utf8mb4?

The way to change a schema's default characters set:
ALTER SCHEMA mysql DEFAULT CHARACTER SET utf8mb4;
However, I don't know if your admin user on RDS has privileges to do that on the mysql system schema. It's possible that you don't, because RDS limits the privileges of your admin user.

Related

character encoding issues when migrating gyroscope app from mysql (latin1) to mariadb (utf8)

I'm migrating a small Gyroscope app from MySQL to MariaDB. I asked this question earlier on why MariaDB would not start on latin1 as server encoding (MariaDB won't start when character-set-server = latin1 is in my.cnf), but now I've come to terms with using just utf8.
After importing the data dump:
mysql -uwebuser -p ezine < dump.sql
, what's supposed to be autotööstus shows up as autot??stus. In addition I got this error:
illegal mix of collations (latin1_general_ci implicit) and (utf8_general_ci coercible), storing ??
Attempt 1: I removed all the occurrences of charset=latin1 in the data dump, and the import terminated early with this error:
Specified key was too long; max key length is 767 bytes
Attempt 2: added back charset, but set it to charset=utf8, according to this post: MySQL Convert latin1 data to UTF8
The import works, but autotööstus is now showing as autotööstus
How do I interpret the data dump as latin1 encoded content but deposit into a utf8 storage?
If you cannot use latin1 as the default system encoding for whatever reason, here's a quick solution:
Leave the data dump as-is. Even though it's latin1 encoded, it can be imported as utf8.
mysql> create database ezine character set utf8 collate utf8_general_ci;
mysql -uwebuser -p --default-character-set=utf8 ezine < dump.sql
Now in your web app, you should correctly see autotööstus
From now on, the "native currency" of your database is utf8. When dumping the database, you have to be careful, make sure the exported file is still latin1 encoded.
Otherwise you'll end up with the over-encoded data, such as autotööstus.
mysqldump -uwebuser -p --default-char-set=latin1 ezine > dump.sql

mysql change default character set latin1 to utf8

I have PHP 5.5.9 and MySQL 5.5.43 Innodb. This is in Kubuntu LTS /etc/mysql/my.cnf
printf("Current character set: %s\n", mysqli_character_set_name($conn));
Current character set: latin1
I've tried
default-character-set = utf8
first but then my mysql server didn't restart
Then I've tried
character-set-server = utf8
then my mysql shell didn't start
How can I rescue this issue? I've managed with
init_connect = 'SET NAMES utf8'
solve the problem for nonroot users, but the charset remains the same (it only displays as nonprivileged users UTF8, it is still Latin1).
And if (a big if) smnd could tell me WHERE should I use utf8mb4? Also in my.cnf file? I had my tables in utf8 and have migrated those with which I am working to utf8mb4 ...
Another Q: IS that applicable for Linux (Kubuntu) server:
https://www.youtube.com/watch?v=3M1Wpw4uOoM
Please help me, thanks, Gregor from lilaum.com
mysqli_set_charset('utf8').
init_connect is ignored for root connections.
utf8mb4 is effectively a superset of utf8. It is needed for Chinese and the new emoji, plus a scattering of obscure character sets.
PHP manual says:
MySQLnd always assumes the server default charset. This charset is sent during connection hand-shake/authentication, which mysqlnd will use.
MySQLnd is the MySQL native driver included with PHP 5.4 and above.
Unfortunately, I have to confirm that even in my system (PHP 5.6.17 with MySQL 5.5.47 on Debian Jessie 8.3) despite having configured /etc/mysql/my.cnf with the following entries
[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8
the mysqlnd does not seem to assume the server default charset (utf8) but sets the connection charset to latin1 with collate latin1_swedish (maybe a default value considering MySQL AB was a swedish company).
So, it seems that there's no permanent way to set utf8 charset when connecting from a PHP application. You have to call
$mysqli->set_charset("utf8")
after each connection. This could be embedded in a custom 'dbconnect' PHP function in order to provide a sort of abstraction layer.

Change variable in MySQL

In MySQL, how to change a variable such as character_set_client?
mysql> show variables like 'character_set%';
-------------------------+-------
character_set_client | latin1
to obtain
character_set_client | utf8
When starting MySQL client you have to specify --default-character-set=charset_name
From manual:
Use charset_name as the default character set for the client and
connection.
A common issue that can occur when the operating system uses utf8
or another multi-byte character set is that output from the mysql
client is formatted incorrectly, due to the fact that the MySQL
client uses the latin1 character set by default. You can usually
fix such issues by using this option to force the client to use the
system character set instead.
For example:
$>mysql -uUser -pPassword --default-character-set=utf8
For an example of how to set it via connection string see here.

Problems setting database character set using mysqladmin

At shell command prompt:
mysqladmin -u"username" -p"password" --default-character-set=utf8 CREATE my_db_schema
--default-character-set=utf8 seems to have no effect and I don't understand why.
Database gets created, but character set is latin1 with collation latin1_swedish_ci.
I found this question, which would seem to be the same issue, but even when I tried a non-root user as the selected answer suggested, I get identical behavior:
MySQL connection character set problems
(I'm using Windows and MariaDB if that makes any difference)
I have tried these mysqladmin.exe clients:
MariaDB 5.3.2 for Win32 (ia32) with default character set latin1 (no .ini)
MySQL 5.0.77 for linux-gnu (i686) with default character set utf8
In both cases, --default-character-set=utf8 or --default-character-set=latin1 do NOT override the MySQL server's .ini/.cnf settings.
As a workaround I'd suggest running:
echo "CREATE DATABASE my_db_schema DEFAULT CHARACTER SET utf8" | mysql -uusername -ppassword
--default-character-set=utf8 seems to have no effect and I don't understand why.
Database gets created, but character set is latin1 with collation latin1_swedish_ci.
This options does not influence the character of a datatabase, table or column when they are created.
The default-character-set is the character set of the connection to the server -- it ensures values you select from the database come through to the client with the correct encoding for display.
On the surface I'd say this appears to be a mysqladmin bug. I would let the MariaDB devs know about it.
http://kb.askmonty.org/en/reporting-bugs has general instructions about reporting bugs (ignore the bit about using the mysqlbug script, since it is not available on Windows).
P.S. And if the bug exists in MariaDB it likely also exists in MySQL.

mysql utf-8 support

when I create a new table, it always is 'latin-swedish-ci' by default. my goal is that this table can store utf-8 text. I tried this way, give me error .
cd C:\mysql-5.5.14-winx64\bin
mysqld --standalone --console --default-storage-engine=InnoDB --default-character-set=utf8
[ERROR] mysqld: unknown variable 'default-character-set=utf8'
Your Database probably has the default charset on latin1 and default collation set to latin1-swedish-ci and so altering the table should help
http://dev.mysql.com/doc/refman/5.1/en/alter-database.html
ALTER DATABASE `MyDatabaseName`
CHARACTER SET utf8
COLLATE utf8_general_ci;
You can always specify column encodings/collations within CREATE TABLE statement. This has additional benefit of making your data structure more portable in case you ever need to move it to another server.