Help us understand the problem. What is going on with this article?

raspberrypi3にmysqlをインストールから文字コード指定まで

More than 3 years have passed since last update.

MySQLのインストール

  • 下記コマンドを実行する。
$ sudo apt-get install mysql-server
  • rootのパスワードを設定する。
    msql_root_pass.jpg
  • 設定したパスワードを再入力する。
    msql_root_pass2.jpg

MySQLクライアントの実行

$ mysql -uroot -p
Enter password:←前項で設定したパスワードを入力
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 43
Server version: 5.5.52-0+deb8u1 (Raspbian)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

文字コード確認

  • 下記コマンドを実行する。
mysql> status
--------------
mysql  Ver 14.14 Distrib 5.5.52, for debian-linux-gnu (armv7l) using readline 6.3

Connection id:          43
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.5.52-0+deb8u1 (Raspbian)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/run/mysqld/mysqld.sock
Uptime:                 28 min 56 sec

Threads: 1  Questions: 584  Slow queries: 0  Opens: 189  Flush tables: 1  Open tables: 41  Queries per second avg: 0.336
--------------
  • 上記の状態ではDBに日本語を保存することができないためlatin1となっている個所をutf8にする。
  • 下記のようにmy.cnfを編集する。
$ sudo vi /etc/mysql/my.cnf 
[client]
default-character-set=utf8

[mysqld]
character-set-server = utf8
  • mysqlを再起動する
$ sudo /etc/init.d/mysql restart
  • utf8になっていることを確認する。
mysql> status
--------------
mysql  Ver 14.14 Distrib 5.5.52, for debian-linux-gnu (armv7l) using readline 6.3

Connection id:          37
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.5.52-0+deb8u1 (Raspbian)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/run/mysqld/mysqld.sock
Uptime:                 19 sec

Threads: 1  Questions: 111  Slow queries: 0  Opens: 48  Flush tables: 1  Open tables: 41  Queries per second avg: 5.842
--------------

参考

データベースを使う(MySQL)

t114
基本的に自分用の備忘録メモとして使っているため、細かいところはご容赦ください。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした