パソコン汎用

Debian jessieでmysqlを設定してみるわ。

インストール

サーバ側を 192.168.122.32, クライアントを 192.168.122.13 とするわね。

サーバ側

# apt-get install mysql-server

パスワードとか問われるままに答える。もちろん別々にするのが正しいけど、よくわからないからユニークなパスワードをひとつ考え、それで統一しておく。

そんで、一般ユーザから起動してみる。

$ sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 5.5.53-0+deb8u1 (Debian)

Copyright (c) 2000, 2016, 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>

うん、入れたわね。

次に登録ユーザをみてみましょう。

mysql> use mysql;
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> select user,host from user;
+------------------+----------------+
| user             | host           |
+------------------+----------------+
| root             | 127.0.0.1      |
| hachikun         | 192.168.122.%  |
| hachikun         | 192.168.122.13 |
| hachikun         | 192.168.122.32 |
| root             | ::1            |
| debian-sys-maint | localhost      |
| root             | localhost      |
| root             | mysql          |
+------------------+----------------+
8 rows in set (0.00 sec)
 
mysql>

なんか登録されているわね。

ちなみにこのユーザ登録は、こんな感じにするのよ。

mysql> create user 'username'@'192.168.122.%' identified by 'password';

これだと、192.168.122.* から接続できるって意味ね。

あ、シングルクォートもちゃんと打ち込んでね。

mysql> create user 'username'@'192.168.122.13' identified by 'password';

これだと、接続元が固定になるの。

データテーブルの作成とかはまた別の話。

ちなみにインストール直後だとローカルホストからの接続しかできないと思う。これは、以下を触るの。

/etc/mysql/my.cnf

$ sudo vi /etc/mysql/my.cnf
bind-address           = 127.0.0.1

これをコメントにしてmysqlサーバを再起動すると、どこからでも接続できるようになるの。

ちなみに、この行を書き換えたり複数並べると、その指定IPからだけ接続もできるんだって。

クライアント側

たぶんruby-mysqlとかあればいいと思うけど、コマンドでも試したいから入れる。

# apt-get install mysql-client

インストールしたら、以下を試してみましょう。

$ mysql -h 192.168.122.32 -u hachikun -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.5.53-0+deb8u1 (Debian)

Copyright (c) 2000, 2016, 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 |
+--------------------+
1 row in set (0.00 sec)

mysql>

うん、接続できたみたいね。

(おまけ)カラのDBを作って許可を与える。

これくらいあれば充分かな。 ユーザーをhachikun、DB名を dbnameで。

作ったユーザーで生成するのが手本になっている資料もあるけど、生成は管理者ができればいい事でしょう。

$ sudo mysql -u 管理者 -p
password:
:
:
> create database dbname;
Query OK, 1 row affected ....
:
> grant all privileges on dbname.* to 'hachikun'@'192.168.1.%';
:
> quit;

あとは、このユーザとDBで手動接続してみることね。


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-11-02 (金) 10:54:51