teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

試したことを追加

2019/04/10 01:43

投稿

shibuchaaaan
shibuchaaaan

スコア19

title CHANGED
File without changes
body CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  コマンドプロンプトからSQL文でINSERTすると日本語のみ文字化けする。
14
14
 
15
- ```command
15
+ ```SQL
16
16
  MariaDB [testdb]> insert into test(name,skill)values('みき','HTML');
17
17
 
18
18
  MariaDB [testdb]> select* from test;
@@ -26,7 +26,7 @@
26
26
  ### 試したこと
27
27
 
28
28
  ①まずはDBの文字コード設定を確認。
29
- ```command
29
+ ```SQL
30
30
  MariaDB [testdb]> show variables like "chara%";
31
31
  +--------------------------+--------------------------------+
32
32
  | Variable_name | Value |
@@ -42,7 +42,7 @@
42
42
  +--------------------------+--------------------------------+
43
43
  ```
44
44
  DBの設定
45
- ```command
45
+ ```SQL
46
46
  MariaDB [testdb]> show create database testdb;
47
47
  +----------+-----------------------------------------------------------------+
48
48
  | Database | Create Database |
@@ -51,7 +51,7 @@
51
51
  +----------+-----------------------------------------------------------------+
52
52
  ```
53
53
  テーブルの設定
54
- ```command
54
+ ```SQL
55
55
  MariaDB [testdb]> desc test;
56
56
  +-------+-------------+------+-----+---------+----------------+
57
57
  | Field | Type | Null | Key | Default | Extra |
@@ -69,7 +69,7 @@
69
69
  ③my.ini[mysql]のdefault-set-characterもutf8に書き換え。
70
70
 
71
71
  DBの設定
72
- ```command
72
+ ```SQL
73
73
  MariaDB [(none)]> show variables like "chara%";
74
74
  +--------------------------+--------------------------------+
75
75
  | Variable_name | Value |
@@ -87,7 +87,7 @@
87
87
 
88
88
  この状態で新たにDB作成し、INSERT
89
89
 
90
- ```command
90
+ ```SQL
91
91
  MariaDB [(none)]> create database test2;
92
92
 
93
93
  MariaDB [test2]> create table table1(id int auto_increment,name varchar(20),skill varchar(20),index(id));
@@ -107,7 +107,7 @@
107
107
  my.iniの[mysql]default-character-setをcp932に書き換え。
108
108
 
109
109
  DB設定
110
- ```command
110
+ ```SQL
111
111
  MariaDB [(none)]> show variables like "chara%";
112
112
  +--------------------------+--------------------------------+
113
113
  | Variable_name | Value |
@@ -125,11 +125,9 @@
125
125
 
126
126
  設定が元通りなので意味ないと思うが、この状態で再度DB作成してINSERT
127
127
 
128
- ```command
128
+ ```SQL
129
129
  MariaDB [(none)]> create database test3;
130
-
131
130
  MariaDB [test3]> create table table3(id int,name varchar(20),skill varchar(20));
132
-
133
131
  MariaDB [test3]> insert into table3(id,name,skill)values(1,'みき','CSS');
134
132
 
135
133
  MariaDB [test3]> select* from table3;
@@ -141,13 +139,11 @@
141
139
  ```
142
140
  ④[https://teratail.com/questions/58424](https://teratail.com/questions/58424)を参考にset namesしてみた
143
141
 
144
- ```command
142
+ ```SQL
145
143
  MariaDB [(none)]> set names cp932;
146
144
 
147
145
  MariaDB [(none)]> create database newone;
148
-
149
146
  MariaDB [newone]> create table tbl3(id int,name varchar(10),skill varchar(10));
150
-
151
147
  MariaDB [newone]> insert into tbl3(id,name,skill)values(1,'みき','HTML');
152
148
 
153
149
  MariaDB [newone]> select* from tbl3;
@@ -165,10 +161,64 @@
165
161
  状況を整理すると、
166
162
  - DBの文字設定全てutf9にしても直らない
167
163
  - 文字設定の中で[character_set_client],[character_set_connection],[character_set_results]がcp932でも直らない
164
+ - ご質問に対して
165
+ 1.どんな感じで文字化けしているか?
166
+ →日本語が「 ・ノ・・」「 ・・・B・E・ォ・・」のようになります。
167
+ 2.プログラムは何を使ってデータを呼び出そうとしているか?
168
+ →データの呼び出し・挿入は全てコマンドプロンプト上で行っています。
168
169
 
169
170
  ということになっています。
170
171
  ご教示いただけると幸いです。
171
172
 
173
+ ###追記
174
+ ご回答をいただき、以下を試してみました。
175
+ - 文字コードを「utfmb4」に設定した
176
+ ```SQL
177
+ MariaDB [(none)]> show variables like "chara%";
178
+ +--------------------------+--------------------------------+
179
+ | Variable_name | Value |
180
+ +--------------------------+--------------------------------+
181
+ | character_set_client | utf8mb4 |
182
+ | character_set_connection | utf8mb4 |
183
+ | character_set_database | utf8 |
184
+ | character_set_filesystem | binary |
185
+ | character_set_results | utf8mb4 |
186
+ | character_set_server | utf8 |
187
+ | character_set_system | utf8 |
188
+ | character_sets_dir | C:\xampp\mysql\share\charsets\ |
189
+ +--------------------------+--------------------------------+
190
+
191
+ MariaDB [test1]> create table test2(id int,name varchar(20))default charset=utf8mb4;
192
+
193
+ MariaDB [test1]> insert into test2(id,name)values(1,'みき');
194
+
195
+ MariaDB [test1]> select* from test2;
196
+ +------+------+
197
+ | id | name |
198
+ +------+------+
199
+ | 1 | ?ン・? |
200
+ +------+------+
201
+ ```
202
+
203
+ - 文字コードをsjisに設定した
204
+ 参照:[https://teratail.com/questions/153238](https://teratail.com/questions/153238)
205
+ ```SQL
206
+ MariaDB [test3]> SET character_set_results = sjis;
207
+ MariaDB [test3]> SET character_set_client = sjis;
208
+
209
+ MariaDB [test3]> create table test2(id int,name varchar(20))default charset=sjis;
210
+ MariaDB [test3]> insert into test2(id,name)values(1,'みき');
211
+
212
+ MariaDB [test3]> select* from test2;
213
+ +------+------+
214
+ | id | name |
215
+ +------+------+
216
+ | 1 | ??? |
217
+ +------+------+
218
+ ```
219
+
172
220
  ### 参考にしたURL
173
221
  [https://teratail.com/questions/135821](https://teratail.com/questions/135821)
174
- [https://teratail.com/questions/124308](https://teratail.com/questions/124308)
222
+ [https://teratail.com/questions/124308](https://teratail.com/questions/124308)
223
+ [https://teratail.com/questions/153238](https://teratail.com/questions/153238)
224
+ [https://qiita.com/deco/items/bfa125ae45c16811536a](https://qiita.com/deco/items/bfa125ae45c16811536a)

1

誤字修正

2019/04/10 01:42

投稿

shibuchaaaan
shibuchaaaan

スコア19

title CHANGED
File without changes
body CHANGED
@@ -63,7 +63,7 @@
63
63
  ```
64
64
 
65
65
 
66
- ここ( https://qiita.com/YusukeHigaki/items/2cab311d2a559a543e3aを参考に、my.iniの[client]と[mysqld]の文字コードをutf8に書き換え。
66
+ [https://qiita.com/YusukeHigaki/items/2cab311d2a559a543e3a](https://qiita.com/YusukeHigaki/items/2cab311d2a559a543e3a)を参考に、my.iniの[client]と[mysqld]の文字コードをutf8に書き換え。
67
67
  DBの設定を確認しましたが、文字コードの設定が最初と変わっていなかったので、
68
68
 
69
69
  ③my.ini[mysql]のdefault-set-characterもutf8に書き換え。
@@ -103,7 +103,7 @@
103
103
  ```
104
104
 
105
105
  これでもダメだったので、
106
- ④https://teratail.com/questions/26559を参考に、
106
+ [https://teratail.com/questions/26559](https://teratail.com/questions/26559)を参考に、
107
107
  my.iniの[mysql]default-character-setをcp932に書き換え。
108
108
 
109
109
  DB設定
@@ -139,7 +139,7 @@
139
139
  | 1 | ・ン・ォ | CSS |
140
140
  +------+------+-------+
141
141
  ```
142
- ④https://teratail.com/questions/58424を参考にset namesしてみた
142
+ [https://teratail.com/questions/58424](https://teratail.com/questions/58424)を参考にset namesしてみた
143
143
 
144
144
  ```command
145
145
  MariaDB [(none)]> set names cp932;
@@ -170,5 +170,5 @@
170
170
  ご教示いただけると幸いです。
171
171
 
172
172
  ### 参考にしたURL
173
- https://teratail.com/questions/135821
173
+ [https://teratail.com/questions/135821](https://teratail.com/questions/135821)
174
- https://teratail.com/questions/124308
174
+ [https://teratail.com/questions/124308](https://teratail.com/questions/124308)