mysql问题求解 
表1:字符集latin1_swedish_ci,有字段:user,password,email,qq,msn等等 
表2:字符集gbk_chinese_ci,有字段:user,password,email 用户到时要求要从表2中读取。 请问如何将表1中的记录插入到表2?最好是能写出语句,万分感谢

解决方案 »

  1.   

    insert into gbk_chinese_ci (user,password,email) select user,password,email  from latin1_swedish_ci
      

  2.   

    用hex, unhex 处理一下就行了。mysql> show full columns from t_gzhuu1;
    +----------+-------------+-------------------+------+-----+---------+-------+---
    | Field    | Type        | Collation         | Null | Key | Default | Extra | Pr
    +----------+-------------+-------------------+------+-----+---------+-------+---
    | user     | varchar(10) | latin1_swedish_ci | YES  |     | NULL    |       | se
    | password | varchar(10) | latin1_swedish_ci | YES  |     | NULL    |       | se
    | email    | varchar(10) | latin1_swedish_ci | YES  |     | NULL    |       | se
    | qq       | varchar(10) | latin1_swedish_ci | YES  |     | NULL    |       | se
    | msn      | varchar(10) | latin1_swedish_ci | YES  |     | NULL    |       | se
    +----------+-------------+-------------------+------+-----+---------+-------+---
    5 rows in set (0.02 sec)mysql> show full columns from t_gzhuu2;
    +----------+-------------+----------------+------+-----+---------+-------+------
    | Field    | Type        | Collation      | Null | Key | Default | Extra | Privi
    +----------+-------------+----------------+------+-----+---------+-------+------
    | user     | varchar(10) | gbk_chinese_ci | YES  |     | NULL    |       | selec
    | password | varchar(10) | gbk_chinese_ci | YES  |     | NULL    |       | selec
    | email    | varchar(10) | gbk_chinese_ci | YES  |     | NULL    |       | selec
    +----------+-------------+----------------+------+-----+---------+-------+------
    3 rows in set (0.00 sec)mysql> insert into t_gzhuu1 (user,password,email)
        -> select unhex(hex(user)),password,email from t_gzhuu2;
    Query OK, 2 rows affected (0.09 sec)
    Records: 2  Duplicates: 0  Warnings: 0mysql>
      

  3.   

    insert into gbk_chinese_ci new_members(username, password, email) select username, password, email from latin1_swedish_ci old_members 这样对吗?
      

  4.   

    下面测试已经正常了啊,你为什么不自己试一下?!mysql> select * from t_gzhuu1;
    Empty set (0.00 sec)mysql> select * from t_gzhuu2;
    +-------+----------+-----------+
    | user  | password | email     |
    +-------+----------+-----------+
    | 记录1 | 123      | [email protected] |
    | 记录2 | 124      | [email protected] |
    +-------+----------+-----------+
    2 rows in set (0.00 sec)mysql> insert into t_gzhuu1 (user,password,email)
        -> select unhex(hex(user)),password,email from t_gzhuu2;
    Query OK, 2 rows affected (0.03 sec)
    Records: 2  Duplicates: 0  Warnings: 0mysql> set names 'latin1';
    Query OK, 0 rows affected (0.00 sec)mysql> select * from t_gzhuu1;
    +-------+----------+-----------+------+------+
    | user  | password | email     | qq   | msn  |
    +-------+----------+-----------+------+------+
    | 记录1 | 123      | [email protected] | NULL | NULL |
    | 记录2 | 124      | [email protected] | NULL | NULL |
    +-------+----------+-----------+------+------+
    2 rows in set (0.00 sec)mysql>