インストール
- MySQL クライアントをインストールする
$ brew install mysql --client-only
- バージョンを確認する
$ mysql --version mysql Ver 14.14 Distrib 5.7.18, for osx10.12 (x86_64) using EditLine wrapper
Amazon Aurora のインスタンスを起動する
接続してみる
- Amazon Aurora に接続する
$ mysql -h mydbinstance-cluster.cluster-******.us-east-1.rds.amazonaws.com -u master -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 55 Server version: 5.6.10 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.20 sec)
- データベースを作成する
mysql> create database test; Query OK, 1 row affected (0.17 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.16 sec)
- 作成したデータベースに接続する
mysql> use test; Database changed
- テーブルを作成する
mysql> create table test(col1 int, col2 varchar(255)); Query OK, 0 rows affected (0.18 sec)
- レコードを insert する
mysql> insert into test(col1, col2) values(1, ' Work hard, Have fun, Make History!! '); Query OK, 1 row affected (0.17 sec) mysql> insert into test(col1, col2) values(2, 'Work hard, Have fun, Make History!!'); Query OK, 1 row affected (0.17 sec)
- insert した行を確認する
mysql> select * from test; +------+-----------------------------------------+ | col1 | col2 | +------+-----------------------------------------+ | 1 | Work hard, Have fun, Make History!! | | 2 | Work hard, Have fun, Make History!! | +------+-----------------------------------------+ 2 rows in set (0.17 sec)
- もう1行 insert して確認してみる
mysql> insert into test(col1, col2) values(1, ' Work hard, Have fun, Make History!! '); Query OK, 1 row affected (0.16 sec) mysql> select * from test; +------+--------------------------------------------------------+ | col1 | col2 | +------+--------------------------------------------------------+ | 1 | Work hard, Have fun, Make History!! | | 2 | Work hard, Have fun, Make History!! | | 1 | Work hard, Have fun, Make History!! | +------+--------------------------------------------------------+ 3 rows in set (0.18 sec)
追記(2017/05/12):
mysql> use mydb Database changed mysql> create table test(col1 int, col2 char(30)); Query OK, 0 rows affected (0.25 sec) mysql> insert into test(col1, col2) values(1, 'Make History!!'); Query OK, 1 row affected (0.23 sec) mysql> select * from test; +------+----------------+ | col1 | col2 | +------+----------------+ | 1 | Make History!! | +------+----------------+ 1 row in set (0.34 sec) mysql> insert into test(col1, col2) values(1, 'Make History!! '); Query OK, 1 row affected (0.23 sec) mysql> select * from test; +------+----------------+ | col1 | col2 | +------+----------------+ | 1 | Make History!! | | 1 | Make History!! | +------+----------------+ 2 rows in set (0.31 sec) mysql> SELECT @@SESSION.sql_mode; +--------------------+ | @@SESSION.sql_mode | +--------------------+ | | +--------------------+ 1 row in set (0.33 sec) mysql> SET SESSION sql_mode='PAD_CHAR_TO_FULL_LENGTH'; Query OK, 0 rows affected (0.25 sec) mysql> SELECT @@SESSION.sql_mode; +-------------------------+ | @@SESSION.sql_mode | +-------------------------+ | PAD_CHAR_TO_FULL_LENGTH | +-------------------------+ 1 row in set (0.23 sec) mysql> SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA = 'Common'; ERROR 2013 (HY000): Lost connection to MySQL server during query