ユーザ用ツール

サイト用ツール


サイドバー

Index

はじめてのおつかい






DokuWiki整形記法


PlayGround



serverapps:db:mysql:connectexternal

外部ホストからのMySQL接続

/usr/local/etc/mysql/my.cnf

bind-addressは接続を絞るためのものなので外部からのアクセスを許可する場合には外す。1)2)

/usr/local/etc/mysql/my.cnfを編集する

全てのIPで待ち受け

# コメントアウト
# bind-address = 127.0.0.1
OR
bind-address = 0.0.0.0

127.0.0.1 でのみ待ち受け

bind-address = 127.0.0.1

指定したアドレスで待ち受け

bind-address = 192.168.0.XXX

この場合、mysql -h 127.0.0.1 で接続できない

保持していないアドレスで待ち受け

bind-address = 192.168.168.XXX

この場合、mysqlが起動しない

2行書いた

bind-address = 192.168.0.XXX
bind-address = 192.168.0.YYY

最後が有効

スペース区切り

bind-address = 192.168.0.XXX 192.168.0.YYY

最初が有効

ユーザの確認

mysql> select user,host from mysql.user;
+------+-----------------------+
| user | host                  |
+------+-----------------------+
| root | 127.0.0.1             |
| root | ::1                   |
|      | localhost             |
| root | localhost             |
|      | localhost.localdomain |
| root | localhost.localdomain |
+------+-----------------------+

存在するデータベースの一覧

mysql> show databases;  
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| synctest           |
| test               |
+--------------------+

ユーザ作成

  • すべてのホスト
mysql> grant all privileges on *.* to user1@"%" identified by 'パスワード' with grant option;
  • LANのみに限定
mysql> grant all privileges on dbname.* to user1@"192.168.0.%" identified by 'パスワード' with grant option;
  • なお、上記だと作成されるのは外部接続のみなので、同様にLocalhostにも作成する。3)
mysql> grant all privileges on dbname.* to user1@"localhost" identified by 'パスワード' with grant option;

ユーザ削除

mysql> drop user 'user'@'localhost';
1)
または接続I/FにBindする
2)
よって、複数指定はできない
3)
作成しないと接続できなかった
serverapps/db/mysql/connectexternal.txt · 最終更新: 2021/05/11 11:29 by hayashi