環境 †
- OS X 10.11 El Capitan
- Homebrew 0.9.9
- MySQL 5.7.13
MySQLインストール †
$ brew install mysql
$ mysql --version
mysql Ver 14.14 Distrib 5.7.13, for osx10.11 (x86_64) using EditLine wrapper
$ mysql.server start
Starting MySQL
.. SUCCESS!
$ mysql.server stop
Shutting down MySQL
. SUCCESS!
セキュリティ設定 †
$ mysql -u root
- rootユーザーのパスワード設定 [#d8321678]
mysql> SET PASSWORD FOR root@localhost=PASSWORD('hoge');
$ mysql -u root -p
データベース&一般ユーザー&テーブル作成 †
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 |
+------+---------+-----------------+----------+