Mysql日記2

#Mysql
```sql

$ heroku config

=== guarded-ocean-~~~~ Config Vars
CLEARDB_DATABASE_URL:     mysql://kokoha_user:kokoha_password@kokoha_host_desu.cleardb.net/heroku_mysqlnousedetukauyo?reconnect=true
DATABASE_URL:             mysql2://kokoha_user:kokoha_password@kokoha_host_desu.cleardb.net/heroku_mysqlnousedetukauyo?reconnect=true
LANG:                     en_US.UTF-8
RACK_ENV:                 production
RAILS_ENV:                production
RAILS_LOG_TO_STDOUT:      enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE:   ~~~~~~~~~~~~~~~~~

$ mysql -u kokoha_user -h kokoha_host_desu.cleardb.net -pkokoha_password
```
ログイン成功

```sql

mysql> show databases;
+------------------------+
| Database               |
+------------------------+
| information_schema     |
| heroku_283b11031154516 |
+------------------------+
2 rows in set (1.98 sec)

mysql> use  heroku_mysqlnousedetukauyo;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------------------------+
| Tables_in_heroku_283b11031154516 |
+----------------------------------+
| ar_internal_metadata             |
| clips                            |
| admin_users                      |
| admins                           |
| customers                        |
| events                           |
| schema_migrations                |
| users                            |
+----------------------------------+
mysql> desc events;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| eventname  | varchar(255) | YES  |     | NULL    |                |
| when       | datetime     | YES  |     | NULL    |                |
| where      | varchar(255) | YES  |     | NULL    |                |
| cost       | int(11)      | YES  |     | NULL    |                |
| created_at | datetime     | NO   |     | NULL    |                |
| updated_at | datetime     | NO   |     | NULL    |                |
| text       | varchar(255) | YES  |     | NULL    |                |
| user_id    | int(11)      | YES  |     | NULL    |                |
| picture    | varchar(255) | YES  |     | NULL    |                |
| picture2   | varchar(255) | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+


mysql> select * from events;
+----+--------------------------------+---------------------+------------+------+---------------------+---------------------+-------------------+---------+---------+----------+
| id | eventname                      | when                | where      | cost | created_at          | updated_at          | text              | user_id | picture | picture2 |
+----+--------------------------------+---------------------+------------+------+---------------------+---------------------+-------------------+---------+---------+----------+
|  1 | Event_id = 1   by_user 1   1/4 | 2018-10-04 15:00:00 | ???????    | NULL | 2018-10-29 10:19:29 | 2018-10-29 10:19:29 | ???????           |       1 | NULL    | NULL     |
| 11 | Event_id = 2  by_user 1    2/4 | 2018-12-24 18:00:00 | ?????C33?? | NULL | 2018-10-29 10:19:29 | 2018-10-29 10:19:29 | ????????????????? |       1 | NULL    | NULL     |
| 21 | Event_id = 3  by_user 1    3/4 | 2018-10-04 13:00:00 | ???        | NULL | 2018-10-29 10:19:29 | 2018-10-29 10:19:29 | ???????           |       1 | NULL    | NULL     |
| 31 | Event_id = 4  by_user 1    4/4 | 2018-10-04 04:00:00 | ????       | NULL | 2018-10-29 10:19:29 | 2018-10-29 10:19:29 | ???????           |       1 | NULL    | NULL     |
+----+--------------------------------+---------------------+------------+------+---------------------+---------------------+-------------------+---------+---------+----------+


mysql> select id from events;
+----+
| id |
+----+
|  1 |
| 11 |
| 21 |
| 31 |
+----+
mysql> select id from events where id < 11;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.24 sec)

mysql> select id from events where id < 21;
+----+
| id |
+----+
|  1 |
| 11 |
+----+
mysql> desc clips;
+-------------+------------+------+-----+---------+----------------+
| Field       | Type       | Null | Key | Default | Extra          |
+-------------+------------+------+-----+---------+----------------+
| id          | bigint(20) | NO   | PRI | NULL    | auto_increment |
| customer_id | bigint(20) | NO   | MUL | NULL    |                |
| event_id    | bigint(20) | NO   | MUL | NULL    |                |
| created_at  | datetime   | NO   |     | NULL    |                |
| updated_at  | datetime   | NO   |     | NULL    |                |
+-------------+------------+------+-----+---------+----------------+
5 rows in set (0.19 sec)

mysql> INSERT INTO clips (customer_id, event_id) VALUES (1, 1);
Query OK, 1 row affected, 2 warnings (0.25 sec)

mysql> select * from clips;
+----+-------------+----------+---------------------+---------------------+
| id | customer_id | event_id | created_at          | updated_at          |
+----+-------------+----------+---------------------+---------------------+
|  1 |           1 |        1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
+----+-------------+----------+---------------------+---------------------+
1 row in set (0.19 sec)
mysql> INSERT INTO clips (customer_id, event_id) VALUES (11, 11);
Query OK, 1 row affected, 2 warnings (0.20 sec)

mysql> select * from clips;
+----+-------------+----------+---------------------+---------------------+
| id | customer_id | event_id | created_at          | updated_at          |
+----+-------------+----------+---------------------+---------------------+
|  1 |           1 |        1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 11 |          11 |       11 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
+----+-------------+----------+---------------------+---------------------+
2 rows in set (0.19 sec)

mysql> exit
Bye
```