關於MySQL DNS解析探究之一:DNS解析確實在起作用

來源:互聯網
上載者:User

標籤:

機器A --> 192.168.103.94  -- 伺服器

機器B --> 192.168.4.2        -- 用戶端

機器A =>

裝上mysql-server,啟動; 使用root使用者登入,查看DNS解析是否開啟,執行如下命令:

mysql> show variables like ‘skip_name_resolve%‘;+-------------------+-------+| Variable_name     | Value |+-------------------+-------+| skip_name_resolve | OFF   |+-------------------+-------+1 row in set (0.00 sec)

說明DNS解析是開啟狀態

在/etc/hosts中添加:

192.168.4.2      mysql_client_host

在mysql中添加使用者testdns,host為192.168.4.2

mysql> grant all privileges on *.* to [email protected]‘192.168.4.2‘ identified by ‘000‘;mysql> select user,host,password from user where user=‘testdns‘; +---------+-------------+-------------------------------------------+| user    | host        | password                                  |+---------+-------------+-------------------------------------------+| testdns | 192.168.4.2 | *B66FEB4CF5216D971C066EB920EC03B27A5A3F40 |+---------+-------------+-------------------------------------------+mysql> flush privileges;

機器B =>

準備一套jdbc的測試程式:

db.driver=com.mysql.jdbc.Driver

db.url=jdbc:mysql://192.168.103.94:3306/test

db.username=testdns

db.password=000

執行“select 1”查詢語句:查詢成功! 

機器A=> 查看串連進程列表:

mysql> show processlist;+----+---------+------------------------+-------+---------+------+-------+------------------+| Id | User    | Host                   | db    | Command | Time | State | Info             |+----+---------+------------------------+-------+---------+------+-------+------------------+|  3 | root    | localhost              | mysql | Query   |    0 | NULL  | show processlist ||  4 | testdns | mysql_client_host:4192 | test  | Sleep   |    2 |       | NULL             |+----+---------+------------------------+-------+---------+------+-------+------------------+

這裡顯示的主機名稱為mysql_client_host,說明dns解析起作用了

繼續猜測當將testdns的host設定為mysql_client_host也可以,來印證下:

mysql> update user set host=‘mysql_client_host‘ where user=‘testdns‘;mysql> select user,host,password from user where user=‘testdns‘;+---------+-------------------+-------------------------------------------+| user    | host              | password                                  |+---------+-------------------+-------------------------------------------+| testdns | mysql_client_host | *B66FEB4CF5216D971C066EB920EC03B27A5A3F40 |+---------+-------------------+-------------------------------------------+mysql> flush privileges;

在機器B上測試 執行“select 1”查詢語句:查詢成功! 

A機器上將/etc/hosts中的192.168.4.2      mysql_client_host 注釋掉, 並且mysql命令列執行flush hosts,因為mysql會緩衝dns解析記錄;

B機器上再次測試,

java.sql.SQLException: null,  message from server: "Host ‘192.168.4.2‘ is not allowed to connect to this MySQL server"

 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)

 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)

 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)

小節:以上測試證明mysql的dns解析確實在起作用


關於MySQL DNS解析探究之一:DNS解析確實在起作用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.