Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4179741
  • 博文数量: 240
  • 博客积分: 11504
  • 博客等级: 上将
  • 技术积分: 4277
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-28 14:24
文章分类

全部博文(240)

分类: Mysql/postgreSQL

2008-02-15 15:28:48

今天发现有个\r 选项可以切换连接。不过功能比较单一。
connect   (\r) Reconnect to the server. Optional arguments are db and host.

进入客户端后切换服务器连接的做法。
只能是切换到和另外一个SERVER端口,用户名,密码都是一样的。
原来SERVER:A。
切换的SERVER:B。
B上的操作:
mysql> grant usage,select on *.* to root@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> status
--------------

/usr/local/mysql/bin/mysql Ver 14.12 Distrib 5.0.45, for pc-linux-gnu (i686) using readline 5.0

Connection id: 9
Current database: mysql
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.0.45-log 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: /tmp/mysql.sock
Uptime: 3 days 6 hours 30 min 0 sec

Threads: 1 Questions: 59 Slow queries: 0 Opens: 12 Flush tables: 1 Open tables: 6 Queries per second avg: 0.000
--------------


mysql> show processlist;
+----+-------------+-----------+------+---------+--------+-----------------------------------------------------------------------+------------------+

| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+------+---------+--------+-----------------------------------------------------------------------+------------------+

| 2 | system user | | NULL | Connect | 282919 | Has read all relay log; waiting for the slave I/O thread to update it | NULL |
| 9 | root | localhost | test | Query | 0 | NULL | show processlist |
+----+-------------+-----------+------+---------+--------+-----------------------------------------------------------------------+------------------+

2 rows in set (0.00 sec)


A上的操作:
mysql> \r test 192.168.0.232
Connection id: 23
Current database: test

mysql> status
--------------

mysql Ver 14.14 Distrib 5.1.22-rc, for redhat-linux-gnu (i686) using readline 5.0

Connection id: 23
Current database: test
Current user: root@192.168.0.231
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.1.22-rc-log MySQL Community Server (GPL)
Protocol version: 10
Connection: 192.168.0.232 via TCP/IP
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 3 days 6 hours 33 min 10 sec

Threads: 2 Questions: 77 Slow queries: 1 Opens: 12 Flush tables: 1 Open tables: 9000 Queries per second avg: 0.000
--------------


mysql> show processlist;
+----+------+---------------------+------+---------+------+-------+------------------+

| Id | User | Host | db | Command | Time | State | Info |
+----+------+---------------------+------+---------+------+-------+------------------+

| 9 | root | localhost | test | Sleep | 25 | | NULL |
| 23 | root | 192.168.0.231:34173 | test | Query | 0 | NULL | show processlist |
+----+------+---------------------+------+---------+------+-------+------------------+

2 rows in set (0.00 sec)

mysql>

连接后B上的操作:
mysql> show processlist;
+----+-------------+---------------------+------+---------+--------+-----------------------------------------------------------------------+------------------+

| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+---------------------+------+---------+--------+-----------------------------------------------------------------------+------------------+

| 2 | system user | | NULL | Connect | 282869 | Has read all relay log; waiting for the slave I/O thread to update it | NULL |
| 9 | root | localhost | test | Query | 0 | NULL | show processlist |
| 23 | root | 192.168.0.231:34173 | test | Sleep | 69 | | NULL |
+----+-------------+---------------------+------+---------+--------+-----------------------------------------------------------------------+------------------+

3 rows in set (0.00 sec)

现在已经连接上了。




阅读(6589) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

骑着蚂蚁过街2008-02-18 09:43:17

我没有看明白是谁连接谁? 如何切换服务器连接的? 您用的linux我的win32操作系统!