登录MySQL后,使用 ?查看帮助,
mysql> ?
For information about MySQL products and services, visit:
http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
https://shop.mysql.com/
List of all MySQL commands:
Note that all text commands must be first on line and end with ‘;’
? (?) Synonym for `help’.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don’t write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (#) Rebuild completion hash.
source (.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don’t show warnings after every statement.
For server side help, type ‘help contents’
每条语句最后的分号;
表示结束 ,否则 MySQL 会认为你的语句不完整无法执行,会等待你继续输入,直到你给出分号;
为止,MySQL 才会去执行你给的语句。
退出 MySQL
mysql> quit
Bye
[root@localhost /]#
客户端 和 MySQL 服务器 都是 192.168.231.*网段的,
[root@localhost /]#
ifconfig
eth2 Link encap:Ethernet HWaddr 00:0C:29:F7:1C:C2
inet addr:192.168.231.131
Bcast:192.168.231.255 Mask:255.255.255.0
使用 sql manager for MySQL 远程连接 数据库,失败,无法获取数据库列表,
这是因为,数据库当前还不允许远程登录数据库,
需要,登录MySQL,配置允许远程登录,
[root@localhost /]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.66 Source distribution
Copyright © 2000, 2012, 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 |
| mysql
|
| test |
±-------------------+
3 rows in set (0.00 sec)
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 是 系统数据库,配置远程登录,就是操作更改系统数据库 MySQL,
mysql> select host,user from user;
±----------------------±-----+
| host | user |
±----------------------±-----+
| 127.0.0.1 | root |
| localhost | |
| localhost | root |
| localhost.localdomain | |
| localhost.localdomain | root |
±----------------------±-----+
查看当前,系统数据库中存在的用户,可以看到,host 列中没有,192.168.231.*网段的,所以客户端无法远程登录MySQL,
需要创建一个远程用户,达到远程登录MySQL的目的,
mysql> grant all privileges on *.* to 'root'@'192.168.231.%' identified by 'root' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user from user;
±----------------------±-----+
| host | user |
±----------------------±-----+
| 127.0.0.1 | root |
| 192.168.231.% | root |
| localhost | |
| localhost | root |
| localhost.localdomain | |
| localhost.localdomain | root |
±----------------------±-----+
6 rows in set (0.00 sec)
mysql> show grants for 'root'@'192.168.231.%';
±-------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@192.168.231.% |
±-------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON . TO ‘root’@‘192.168.231.%’ IDENTIFIED BY PASSWORD ‘*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B’ WITH GRANT OPTION |
±-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
创建完成,尝试使用Windows 客户端远程登录MySQL,
可以看到数据库名了,
如果出现长时间都无法列出数据名,是因为卡在主机名逆向解析这里了,
主机名逆向解析,是指,通过客户端的ip地址,去查找对应的主机名,
所以为了加快客户端远程连接MySQL,需要配置MySQL 配置文件 MY.CNF,来跳过主机名逆向解析这个过程,这样MySQL就不用去查找客户端ip地址对应的主机名了,直接看客户端的ip是否在自己的允许范围内,就可以允许/禁止 客户端远程访问MySQL了,
[root@localhost /]# vi /etc/my.cnf
[mysqld
]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
skip-name-resolve
在 MySQLd里添加 skip-name-resolve
保存退出,
重启 MySQL 服务
[root@localhost /]# service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]