MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
Onils
V2EX  ›  MySQL

如何把查询出来的数据再导入 mysql 做表?

  •  
  •   Onils · Sep 1, 2016 · 3189 views
    This topic created in 3567 days ago, the information mentioned may be changed or developed.
    我用 select ..join 语句提取出想要的数据了,导出的是数据文件, 如何把数据导入新表中,或者有其他方式能写入数据库 ?
    6 replies    2016-09-01 17:09:20 +08:00
    bugsnail
        1
    bugsnail  
       Sep 1, 2016
    你需要 insert into table_name select ...join

    注意用别名 0 id, xx name 这样把你 select 的字段匹配对应 table 的字段就行了
    phx13ye
        2
    phx13ye  
       Sep 1, 2016
    You can create one table from another by adding a SELECT statement at the end of the CREATE TABLE statement:

    CREATE TABLE new_tbl [AS] SELECT * FROM orig_tbl;
    Onils
        3
    Onils  
    OP
       Sep 1, 2016
    @bugsnail 数据比较多,能有直接导入文件的么
    Onils
        4
    Onils  
    OP
       Sep 1, 2016
    @phx13ye 这个我试过,语句是可以的,只是我的环境下不能用,所以想想有没其他方式
    mayokelo
        5
    mayokelo  
       Sep 1, 2016
    LOAD DATA INFILE
    bugsnail
        6
    bugsnail  
       Sep 1, 2016
    @Onils 直接导也是一样执行 SQL 语句的

    如果你不需要写到程序里,你可以把导出的数据再用 navicat 这样的工具导进去,只不过用文件的话格式很重要,还有一些其它坑(内容编码,特殊字符等)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1216 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 23:34 · PVG 07:34 · LAX 16:34 · JFK 19:34
    ♥ Do have faith in what you're doing.