前提・実現したいこと
PHP初心者です。テキスト(PHP7+MariaDB/MySQlマスターブック)を参考にしてやっています。
発生している問題・エラーメッセージ
xamppを使用してMySQlをWindows10のコマンドプロンプトで操作しています。
テーブルを作り、INSERT文を使ってカラムに文字列(漢字)を入力しました。
しかし、SELECT文を使って入力した内容を確認したら文字化けをしていました。
対処法としてchcp 65001と打ち、INSERT文を実行しようとすると'>とだけ出力され動かなくなりました。
仕方ないのでctrl + cでMySQLを強制終了させました。
再起動や、他のテーブルを作り試してみましたが同じようになりました。
エラーコード
Setting environment for using XAMPP for Windows.
user@xxxxxxx-xxxxxxx c:\xampp
cd mysql
user@xxxxxxx-xxxxxxx c:\xampp\mysql
cd bin
user@xxxxxxx-xxxxxxx c:\xampp\mysql\bin
mysql -u sample -p
Enter password: *********
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.4.11-MariaDB mariadb.org binary distribution
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)]> use sampledb
Database changed
MariaDB [sampledb]> show tables;
+--------------------+
| Tables_in_sampledb |
+--------------------+
| member |
+--------------------+
1 row in set (0.001 sec)
MariaDB [sampledb]> INSERT INTO member (last_name, first_name, age) VALUES ('田中','一郎',21);
Query OK, 1 row affected, 2 warnings (0.250 sec)
MariaDB [sampledb]> \q
Bye
user@xxxxxxx-xxxxxxx c:\xampp\mysql\bin
mysql -u sample -p --default-character-set=utf8 sampledb
Enter password: *********
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.4.11-MariaDB mariadb.org binary distribution
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 [sampledb]> INSERT INTO member (last_name, first_name, age) VALUES ('山田','二郎',18);
Query OK, 1 row affected, 2 warnings (0.180 sec)
MariaDB [sampledb]> SELECT * FROM member;
+----+-----------+------------+------+
| id | last_name | first_name | age |
+----+-----------+------------+------+
| 1 | ?c?? | ???Y | 21 |
| 2 | ?R?c | ???Y | 18 |
+----+-----------+------------+------+
2 rows in set (0.034 sec)
MariaDB [sampledb]> \q
Bye
user@xxxxxxx-xxxxxxx c:\xampp\mysql\bin
mysql -u sample -p --default-character-set=utf8 sampledb < work.sql
指定されたファイルが見つかりません。
user@xxxxxxx-xxxxxxx c:\xampp\mysql\bin
mysql -u sample -p
Enter password: *********
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.4.11-MariaDB mariadb.org binary distribution
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)]> use sampledb
Database changed
MariaDB [sampledb]> \q
Bye
user@xxxxxxx-xxxxxxx c:\xampp\mysql\bin
chcp 65001
Active code page: 65001
user@xxxxxxx-xxxxxxx c:\xampp\mysql\bin
mysql -u sample -p
Enter password: *********
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.4.11-MariaDB mariadb.org binary distribution
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)]> use sampledb
Database changed
MariaDB [sampledb]> INSERT INTO member (last_name, first_name, age) VALUES ('林','三郎',35);
'>
'>
'>
回答2件
あなたの回答
tips
プレビュー