Mac OS X に MySQL をインストール Vol.3

「Mac OS X に MySQL をインストール Vol.2」の 7 で、
/usr/local/mysql/bin/mysqladmin -u root password <password>
はエラーなくても、
/usr/local/mysql/bin/mysqladmin -u root -h hostname password <password>
では、必ず下記のエラーが起きる。

/usr/local/mysql/bin/mysqladmin: connect to server at ‘[RendezvousName].local ‘ failed
error: ‘Host ‘xxx.xxx.xxx.xxx‘ is not allowed to connect to this MySQL server’

これってどーゆーことなのだろ?
バックダッシュごとhostnameをlocalhostに換えてやりゃどーだ?
ダメ・・・
んじゃなんやねん?と調査開始!


紆余曲折の結果、本家のメーリングリストの過去ログに、バッチリなのを発見。
「install: config root user fails」が質問メール内容。
勝手に転記する。(笑)

Installed the binary distribution packages for Mac OS X:
mysql-max-4.0.l8.pkg
MySQLStartupItem.pkg
no problem.
But then when trying to configure the root user for the
db, cut and paste straight from Chapter 2 of the manual
fails:
$ mysqladmin -u root password “asdf”
$ mysqladmin -u root -h hostname password “asdf”
mysqladmin: connect to server at ‘quickbeam.local’ failed
error: ‘Host ‘192.168.1.100’ is not allowed to connect to this MySQL server’
Please help point me in the right direction

どやさ!全く同じ話だべ。
んで、回答者Michael*1君の登場!
で、例によって勝手に転載。

mysql_install_db created users root@localhost and root@quickbeam.local without paswords. The following two mysqladmin commands are meant to set the passwords:


mysql_instal_dbがroot@localhostとroot@[RendezvousName].localとふたつのユーザーをパスワードなしで作ったわけさ。
例の2行の mysqladminコマンドは、これらにパスワードをセットしようっちゅーこと。[bison意訳]

> $ mysqladmin -u root password “asdf”
Here you connect via the unix socket as root@localhost and set a password.
Good.


この一行めは、unix socket 経由で、root@localhost として接続して、パスワードをセットしたわけだわな。
ここまでは、おーてる、おーてる。

> $ mysqladmin -u root -h hostname password “asdf”
> mysqladmin: connect to server at ‘quickbeam.local’ failed
> error: ‘Host ‘192.168.1.100’ is not allowed to connect to this MySQL
> server’
Here you try to connect via tcp as root@quickbeam.local to set a password,
but it doesn’t work. Note that mysql says “Host ‘192.168.1.100’ is not
allowed to connect…”. It didn’t say “Host ‘quickbeam.local’ is not
allowed to connect…”. That’s the problem — mysql sees the connection
attempt as coming from 192.168.1.100 rather than quickbeam.local. This is
because your DNS does not equate that hostname with that IP number, which is
to be expected with your setup (router and cable/DSL modem).
So, root@quickbeam.local still has no password, but cannot connect either.
Fortunately, you don’t really need this user.


この2行めは、tcp経由でroot@[RendezvousName].localとして接続して、パスワードをセットしようとしたわけだ。
んで、あかんかったと・・・ちょいと、よー見てみ。
mysqlは「xxx.xxx.xxx.xxxが接続を許されてへん」と言うてるわけであって、
[RendezvousName].localが接続を許されてへん」とは言うてへんわけや。
mysqlは[RendezvousName].localからの接続よりも、xxx.xxx.xxx.xxxからの接続を見てるわけや。
これは何でかというと・・・
DNSがhostnameをIPアドレスと同じやとみなしてないからやがな。
ルータとかケーブルモデムとかの設定で出来てなあかんはずやねんけどな。
「MySQL の DNS の使用」(本家内の日本語ページ)参照
せやから、root@[RendezvousName].localは、未だにパスワードが無いわ、接続できへんわ、という状態のままやな。
ま心配せんでも、ホンマはこのユーザーは必要ないねん。

Connect as root@localhost with
mysql -u root -p
You’ll be prompted for the root@localhost password that you set. At the
mysql prompt, enter
DELETE FROM mysql.User WHERE Host ‘localhost’;
FLUSH PRIVILEGES;
The first line gets rid of any tcp users, such as root@quickbeam.local.
The second line makes the change take effect.


root@localhostとして接続するでぇ。具体的には、
mysql -u root -p
やな。ほんだら、例のコマンドの一行めで設定したパスワードを聞かれるはずやから、入れる・・・と。
mysql > なんてなってるところへ下記の2行を入れる。
DELETE FROM mysql.User WHERE Host ‘localhost’;
FLUSH PRIVILEGES;

1行目は、root@[RendezvousName].localみたいなユーザーを削除するわけね。
2行目は、それを有効にする。

Some additional suggestions:
Enter
GRANT ALL ON test.* to douglasdd@localhost IDENTIFIED BY ‘some_password’;
at the mysql prompt to create yourself as a mysql user with full access to
the test db.


もっと言うなら、mysql > ってなってるところに、
GRANT ALL ON [hoge].* to [username]@localhost IDENTIFIED BY ‘some_password’;
って入力してみそ。
チミ自身を、[hoge].dbにフルアクセスのユーザーとして登録ちゅーこと。

If at some point you find that you need root to be able to connect from
quickbeam.local via TCP, you can enter
GRANT ALL ON *.* to root@192.168.1.100 IDENTIFIED BY ‘some_password’;
at the mysql prompt, replacing some_password with an appropriate password.


なんかの都合で、例の2行目がうまくいったのと同じ結果が欲しいとなったら、mysql > の状態で、
GRANT ALL ON *.* to root@xxx.xxx.xxx.xxx IDENTIFIED BY ‘some_password’;
とやってやればいいわけさ。ふん。
あ、それからさっきから some_password って何度も出てくるけど、ここには好きなパスワードを割り当てるねんで。

なりゅほどねん。
[以下2004/4/24追記]
パスワードなしのuser(Defaultではtestというユーザーアカウントがある)を削除しておくのも重要ね。
mysql -$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26 to server version: 4.0.18-standard
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
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> DELETE FROM user WHERE Password = “”\g
Query OK, 1 row affected (0.41 sec)
ってな感じ。
[以下2004/04/26追加]
Spencerさんからこの件について、以下のように教えて頂いた。

-hはhostnameに指定されたHOSTに接続して作業を行う事を意味しています。
で、、、password というのはパスワードをセットする時に使用する
コマンドです。-h なしで接続する場合は sockという形式で接続します。
/tmp/mysql.sock
のような感じですね。ですから、ROOT権限(システムのROOT権限という意味)
で作業をしていればパスワードの設定は許可されます。しかし -h でアクセスした
場合は、TCP経由でアクセスします。ですから、外部からアクセスして来た事にな
ります。この場合にパスワードをセットしたい場合は、
/usr/local/mysql/bin/mysqladmin -u root -p[現在のパスワード] -h hostname password
このようになります。

ふむふむ・・・やっと分かってきた。
sockが今ひとつ単純な理解状態である点をのぞいては、このあたりはOKです。
ありがとうございます。m(_”_)m

  • 注1かの堕天使ルシファーを天界から追放した天使の名前と同じとは、これは神のおぼしめしか?(^m^)ぷぷぷ

コメント

タイトルとURLをコピーしました