社内se × プログラマ × ビッグデータ

プログラミングなどITに興味があります。

Docker mysql8.0 コンテナ作成した後

mysql に root でログイン

$ docker-compose exec mysql8-db bash -c 'mysql -uroot'

新しいユーザーの作成
grant コマンドで一気に作成しようとするが失敗。mysql8では許されていないらしい。

mysql> grant all privileges on *.* to 'blueskyarea'@'localhost' identified by 'area';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'area'' at line 1

以下のように create user でユーザー作成してから、grant で権限追加する。

mysql> create user 'blueskyarea'@'localhost' identified by 'area';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all on *.* to 'blueskyarea'@'localhost' with grant option;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

作成したユーザーでログイン

mysql> quit;
Bye
$ docker-compose exec mysql8-db bash -c 'mysql -ublueskyarea -parea'

データベースの生成
データベースを生成して選択する。

mysql> create database bluesky;
Query OK, 1 row affected (0.01 sec)

mysql> use bluesky;
Database changed

データのインポート

mysql> source /tmp/SQLExample.sql
Query OK, 1 row affected (0.01 sec)