** 環境 [#d4929b5e]

- OS X 10.11 El Capitan
- Homebrew 0.9.9
- MySQL 5.7.13

** MySQLインストール [#ga774b31]

- Homebrewを使ってMySQLインストール

 $ brew install mysql
 $ mysql --version
 mysql  Ver 14.14 Distrib 5.7.13, for osx10.11 (x86_64) using  EditLine wrapper

- MySQLサーバー起動確認

 $ mysql.server start
 Starting MySQL
 .. SUCCESS!

- MySQLサーバー停止

 $ mysql.server stop
 Shutting down MySQL
 . SUCCESS!

** セキュリティ設定 [#lb265a1b]

- MySQLにログイン

 $ mysql -u root

** rootユーザーのパスワード設定 [#d8321678]
- rootユーザーのパスワード設定 [#d8321678]

 mysql> SET PASSWORD FOR root@localhost=PASSWORD('hoge');

- MySQLに再ログイン

 $ mysql -u root -p

** データベース&一般ユーザー&テーブル作成 [#a533edcf]

- データベースを作成

 mysql> create database test;
 mysql> show databases;
 +--------------------+
 | Database           |
 +--------------------+
 | information_schema |
 | mysql              |
 | performance_schema |
 | sys                |
 | test               |
 +--------------------+

- testテーブル操作用のdbuser001ユーザー作成(パスワードは"dbpwd0001")

 mysql> grant all on test. * to dbuser001@localhost identified by 'dbpwd0001';

- テーブルを作成

 mysql> use test;
 mysql> create table users (id int, name varchar(50), email varchar(255), password varchar(16));
 mysql> show tables;
 +----------------+
 | Tables_in_test |
 +----------------+
 | users          |
 +----------------+

- レコードを挿入

 mysql> insert into users (id, name, email, password) values (1, 'kimura', 'kimura@foo.com', 'kimpwd');
 mysql> insert into users (id, name, email, password) values (1, 'tanaka', 'tanaka@foo.com', 'tanapwd');
 mysql> insert into users (id, name, email, password) values (1, 'yoshida', 'yoshida@foo.com', 'yoshipwd');

 mysql> select * from users;
 +------+---------+-----------------+----------+
 | id   | name    | email           | password |
 +------+---------+-----------------+----------+
 |    1 | kimura  | kimura@foo.com  | kimpwd   |
 |    1 | tanaka  | tanaka@foo.com  | tanapwd  |
 |    1 | yoshida | yoshida@foo.com | yoshipwd |
 +------+---------+-----------------+----------+

- レコードを更新

 mysql> update users set id = 2 where name = 'tanaka';
 mysql> update users set id = 3 where name = 'yoshida';

 mysql> select * from users;
 +------+---------+-----------------+----------+
 | id   | name    | email           | password |
 +------+---------+-----------------+----------+
 |    1 | kimura  | kimura@foo.com  | kimpwd   |
 |    2 | tanaka  | tanaka@foo.com  | tanapwd  |
 |    3 | yoshida | yoshida@foo.com | yoshipwd |
 +------+---------+-----------------+----------+


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS