0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

phpMyAdminが文字化けした --20年(?)ぶりにLinuxをいじってみる06

Last updated at Posted at 2023-01-18

全8回の6 → 1|2|3|4|5|6|7|8

Mysqlに日本語データを登録するphpを書いて実行したら、phpMyAdmin上で文字化けを起こしていたという話。
登録データをphpで引っ張り出してみたところ、ブラウザ上では特に化けておらず、ん~? というわけで困ったらググる。

MariaDB, インストール直後にやるべき作業。初期設定は常識です。 | ただ屋ぁのブログ

常識を知らなくてごめんなさい。

# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 56
Server version: 10.5.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>  show variables like "%char%";
+--------------------------+------------------------------+
| Variable_name            | Value                        |
+--------------------------+------------------------------+
| character_set_client     | utf8                         |
| character_set_connection | utf8                         |
| character_set_database   | latin1                       |
| character_set_filesystem | binary                       |
| character_set_results    | utf8                         |
| character_set_server     | latin1                       |
| character_set_system     | utf8                         |
| character_sets_dir       | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+
8 rows in set (0.001 sec)

要するにサーバーサイドでの文字セットがUTF-8でないということだそうな。
参考サイトには「mysql-clients.cnf」と「server.cnf」を直せと書いてあったが

# ls -l /etc/my.cnf.d/
合計 24
-rw-r--r--. 1 root root   42  8月 10 01:58 auth_gssapi.cnf
-rw-r--r--  1 root root  327 12月 19 10:22 client.cnf
-rw-r--r--. 1 root root  763  5月 18  2022 enable_encryption.preset
-rw-r--r--  1 root root 1488 12月 19 10:25 mariadb-server.cnf
-rw-r--r--. 1 root root  232  5月 18  2022 mysql-clients.cnf
-rw-r--r--. 1 root root  120  5月 18  2022 spider.cnf

どちらもない…。
まあmy.cnf.d配下の*.cnfファイルならどこに書いても読み込みはされるということらしいが、一応

client.cnf
[client]
default-character-set = utf8mb4

mariadb-server.cnf
[mysqld]
character-set-server = utf8mb4

と入れて保存し、

# systemctl restart mariadb

で再度

# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 57
Server version: 10.5.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like "%char%";
+--------------------------+------------------------------+
| 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                         |
| character_sets_dir       | /usr/share/mariadb/charsets/ |
+--------------------------+------------------------------+
8 rows in set (0.001 sec)

いったん文字化けしてしまったデータは直らないそうなので、中身を消して入れ直して無事完了。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?