Learning Mysql



Download 4.24 Mb.
View original pdf
Page285/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   281   282   283   284   285   286   287   288   ...   366
Learning MySQL
Users and Hosts | 311

Including the
--host=localhost actually has no effect, since localhost is the default anyway. Now, let’s try specifying the IP address for localhost
; this is always 127.0.0.1:
$ mysql --user=hugh -host --password=the_password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47 to server version 5.0.22-standard-log
Type 'help' or 'h' for help. Type 'c' to clear the buffer.
mysql>
The result is another successful connection, since localhost and 127.0.0.1 are the same system, and MySQL matches the request for host 127.0.0.1 against the privileges for localhost
Now, let’s try connecting to the MySQL server on ruttle from ruttle by using its IP
address:
$ mysql --user=hugh -host --password=the_password
ERROR 1130 (): #HY000Host '192.168.1.2' is not allowed to connect to this
MySQL server
This time, the connection isn’t successful. If you replace with ruttle.invy home.com
, you’ll seethe same problem. Let’s explore why we can’t connect.
At the beginning of this section, we allowed access to the user 'hugh'@'localhost'
That’s exactly what the MySQL server is enforcing we can only connect from the localhost
, and not from anywhere else, including from the actual IP address or domain of the localhost machine. If you want to allow access from 192.168.1.2 (and its equivalent domain name ruttle.invyhome.com
), you need to grant those privileges by creating anew user with the username hugh and the host 192.168.1.2. Note that each username and host pair is treated as a separate user and has its own password.
Log into the monitor as the root user, and type:
mysql> GRANT ALL ONTO 'hugh'@'192.168.1.2' IDENTIFIED BY 'the_password';
Query OK, 0 rows affected (0.00 sec)
Now, quit the monitor and try connecting as the user hugh
:
$ mysql --user=hugh -host --password=the_password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 50 to server version 5.0.22-standard-log
Type 'help' or 'h' for help. Type 'c' to clear the buffer.
mysql>
You’ll also find you can now connect using ruttle.invyhome.com in place of, as long as you’ve got a correctly configured domain nameserver (DNS)
setup. If you have trouble connecting to the MySQL server, refer to the checklist in
“Client Programs Can’t Connect to the Server in Chapter 2.

Download 4.24 Mb.

Share with your friends:
1   ...   281   282   283   284   285   286   287   288   ...   366




The database is protected by copyright ©ininet.org 2024
send message

    Main page