MySQL login:
mysql -u root -p
password
/////////////////////////////////////////////
DBの削除:
mysql> DROP DATABASE user; ※削除
DB設定 (DB名:userの場合)
mysql> CREATE DATABASE user DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> GRANT ALL PRIVILEGES ON user.* TO ‘username’@’localhost’ IDENTFIED BY ‘password’;
mysql> FLUSH PRIVILEGES;
/////////////////////////////////////
MySQL文字化け対策:文字のエンコードをUTF8に設定する。
/etc/mysql/my.cnfを編集して、以下を追記する。
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
skip-character-set-client-handshake
[mysqldump]
default-character-set=utf8
[mysql]
default-character-set=utf8
保存後、mysqlをRestart
sudo service mysql restart
/////////////////////////////////////
mysqlでchractersetを確認:
mysql> SHOW DATABASES;
+———————–+
| Database |
+———————–+
| information_schema |
| mysql |
| performance_schema |
| sys |
| user |
| wordpress |
| wordpress_public_html |
+———————–+
7 rows in set (0.00 sec)
mysql> use user;
Database changed
mysql> show variables like ‘character%’;
+————————–+—————————-+
| Variable_name | Value |
+————————–+—————————-+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+————————–+—————————-+
8 rows in set (0.00 sec)
mysql> show global variables like ‘character%’;
+————————–+—————————-+
| Variable_name | Value |
+————————–+—————————-+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+————————–+—————————-+
8 rows in set (0.01 sec)