20年ぶりにLinuxをいじることで、phpMyAdminが文字化けしてしまった
全8回的6 → 1|2|3|4|5|6|7|8
当我写了一个用于将日语数据存入Mysql的php程序并执行后,在phpMyAdmin上出现了乱码问题的情况。
当我尝试用php将注册的数据提取出来时,在浏览器上并没有发现乱码现象,这让我感到困惑。于是我决定上网搜索找解决方法。
MariaDB安装后应执行的任务。初始设置是常识。 | Tada屋的博客
对不起,我不了解常识。
# 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]
default-character-set = utf8mb4
略读:“と”
[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)
据说,一旦数据发生乱码就无法修复,所以我把内容清空后重新输入,顺利完成。