如题 mysql的

解决方案 »

  1.   

    一样的,在表前面添加数据库名称 例如
    select t1.* from db1.t1 as t1 join db2.t2 as t2 on t1.id=t2.id
      

  2.   

    MYSQL目前不支持跨服务器的查询,导入到一个中查询吧,没有链接服务器的概念
      

  3.   

    还是可以这样,不过您需要链接到另外一个资料库的表格,参见
    http://dev.mysql.com/doc/refman/5.1/zh/storage-engines.html#federated-storage-engine如果不能链接,您或者把数据导到1个mysql系统,然后再作!
      

  4.   

    两个数据库服务器上的则没有办法。
    目前的MYSQL版本还不支持 database link
      

  5.   


    federated-storage可以连接到其他mysql服务器的资料表的
    从MySQL 5.1.26开始,默认安装没有启用federated-storage,您可以添加下面的配置到配置文件my.cnf或my.ini启用
    [mysqld]
    federated末学在本机安装了两个mysql 端口是3306 3307 测试如下(3307端口的开启了federated)C:\Users\coolwind>mysql -uroot -p -P3306 -h127.0.0.1
    Enter password: **********mysql> use test;
    Database changed
    mysql> drop table if exists `test_table`;
    Query OK, 0 rows affected (0.00 sec)mysql> CREATE TABLE `test_table` (
        ->   `id` int(20) NOT NULL AUTO_INCREMENT,
        ->   `name` varchar(32) NOT NULL DEFAULT '',
        ->   `other` int(20) NOT NULL DEFAULT '0',
        ->   PRIMARY KEY (`id`),
        ->   KEY `name` (`name`),
        ->   KEY `other_key` (`other`)
        -> ) DEFAULT CHARSET=utf8;
    Query OK, 0 rows affected (0.02 sec)mysql> insert into test_table(name) values('a'),('b'),('c'),('d');
    Query OK, 4 rows affected (0.00 sec)
    Records: 4  Duplicates: 0  Warnings: 0mysql> select * from test_table;
    +----+------+-------+
    | id | name | other |
    +----+------+-------+
    |  1 | a    |     0 |
    |  2 | b    |     0 |
    |  3 | c    |     0 |
    |  4 | d    |     0 |
    +----+------+-------+
    4 rows in set (0.00 sec)mysql> exit
    Bye
    C:\Users\coolwind>mysql -uroot -P3307 -h127.0.0.1 -p
    Enter password:mysql> use test;
    Database changed
    mysql> drop table if exists test_table;
    Query OK, 0 rows affected, 1 warning (0.02 sec)mysql> CREATE TABLE `test_table` (
        ->   `id` int(20) NOT NULL AUTO_INCREMENT,
        ->   `name` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
        ->   `other` int(20) NOT NULL DEFAULT '0',
        ->   PRIMARY KEY (`id`),
        ->   KEY `name` (`name`),
        ->   KEY `other_key` (`other`)
        -> ) ENGINE=FEDERATED DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci CONNECTIO
    N='mysql://root:[email protected]:3306/test/test_table';
    Query OK, 0 rows affected (0.06 sec)mysql> select * from test_table;
    +----+------+-------+
    | id | name | other |
    +----+------+-------+
    |  1 | a    |     0 |
    |  2 | b    |     0 |
    |  3 | c    |     0 |
    |  4 | d    |     0 |
    +----+------+-------+
    4 rows in set (0.01 sec)mysql> drop table if exists test;
    Query OK, 0 rows affected (0.00 sec)mysql> CREATE TABLE `test` (
        ->   `id` int(11) NOT NULL AUTO_INCREMENT,
        ->   `age` tinyint(3) unsigned DEFAULT NULL,
        ->   PRIMARY KEY (`id`)
        -> ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    Query OK, 0 rows affected (0.03 sec)mysql> insert into test(age) values(80);
    Query OK, 1 row affected (0.00 sec)mysql> select * from test as t1 join test_table as t2 on t1.id=t2.id;
    +----+------+----+------+-------+
    | id | age  | id | name | other |
    +----+------+----+------+-------+
    |  1 |   80 |  1 | a    |     0 |
    +----+------+----+------+-------+
    1 row in set (0.00 sec)mysql> exit
    Bye
      

  6.   

    楼上 loveflea(coolwind)    的好办法! 用 FEDERATED  引擎。学习