Ich benutze das Root-Konto erstellt das Konto 'a'@'%'
. Ich kann das Konto jedoch nicht verwenden, um eine Verbindung zum MySQL-Server herzustellen, wenn ich den Host-Parameter angebe. Ich kann erfolgreich ohne den -h
Parameter verbinden. Bitte beachten Sie das Transkript unten. Ich hoffe, jemand kann mir helfen, es zu erklären. Vielen Dank.
mysql> grant all on *.* to 'a'@'%' identified by a;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a' at line 1
mysql> grant all on *.* to 'a'@'%' identified by 'a';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'a'@'%';
+-----------------------------------------------------------------------------------------------------------+
| Grants for a@% |
+-----------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'a'@'%' IDENTIFIED BY PASSWORD '*667F407DE7C6AD07358FA38DAED7828A72014B4E' |
+-----------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
[root@localhost ~]# mysql -h localhost -u a -p
Enter password:
ERROR 1045 (28000): Access denied for user 'a'@'localhost' (using password: YES)
[root@localhost ~]# mysql -h 127.0.0.1 -u a -p
Enter password:
ERROR 1045 (28000): Access denied for user 'a'@'localhost' (using password: YES)
[root@localhost ~]# mysql -u a -p
Enter password:
ERROR 1045 (28000): Access denied for user 'a'@'localhost' (using password: YES)
[root@localhost ~]# mysql -u a
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.5.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, 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> status
--------------
mysql Ver 14.14 Distrib 5.5.17, for Linux (x86_64) using readline 5.1
Connection id: 20
Current database:
Current user: a@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.17 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 15 days 15 hours 20 min 18 sec
Threads: 1 Questions: 40 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 4 Queries per second avg: 0.000
--------------
mysql>
Bearbeiten:
Ja, MySQL lauscht auf Port 3306.
[root@localhost ~]# nmap localhost
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2012-01-18 07:35 CST
Interesting ports on localhost.localdomain (127.0.0.1):
Not shown: 1674 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
111/tcp open rpcbind
631/tcp open ipp
840/tcp open unknown
3306/tcp open mysql
Nmap finished: 1 IP address (1 host up) scanned in 0.064 seconds
[root@localhost ~]#
'a'@'%'
. Der erste Datensatz war also'a'@'%'
und der zweite ist'a'@'localhost'
.