zoukankan      html  css  js  c++  java
  • MySQL导入导出

    例如sqlite3数据库导入mysql需要一个转换

    这里直接转换的数据库名字就会保存到进入控制台当前默认路径

    退出之后先进入mysql

    在进入到已经创建好为空的数据库进行导入

    1、第一种方式

    source sql文件路径

    进行导入直接看看SQL文件编码是否所需

    如我的mysql是utf-8

    那么就要在数据插入前加入这么一条语句、

    判读数据库是否有这个表有就干掉  drop table if exists lagou_position;

     enter

     2、第二种方式

    导入mysql 进入到空的数据库

    第一步 设置编码 set names utf8;

    第二步 改变事物 set autocommit=0;

    第三步 开始导入 source DB.SQL文件路径

     导出数据

     3、第一种方式

    使用jdbc导入

    这里的DBUtil是连接mysql数据库

    DBUtil连接的是sqlite数据库

    public static void dataMigration() {
    //连接SQLite获得数据集
    ResultSet rs = DBUtil2.executeQuery("select * from lagou_position ");
    String sql = "INSERT INTO lagou_position VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    int sum = 0;
    try {
    //关闭事物
    DBUtil.getConnection().setAutoCommit(false);
    PreparedStatement ps = DBUtil.getConnection().prepareStatement(sql);
    //循环数据插入到mysql中
    //?rewruteBach
    while (rs.next()) {
    for (int i = 1; i <= 19; i++) {
    ps.setObject(i, rs.getObject(i));
    }
    sum++;
    //临时缓存
    ps.addBatch();
    //每隔两x提交一次
    if(sum % 10000 == 0){
    ps.executeBatch();
    }
    }
    ps.executeBatch();
    System.out.println(sum);
    //开启事物
    DBUtil.getConnection().setAutoCommit(true);
    //关闭相关连接
    ps.close();
    DBUtil.close();
    DBUtil2.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
  • 相关阅读:
    推荐一款超棒的阅读App
    IntelliJ中的main函数和System.out.println()快捷键
    oracle中varchar2字段存入blob字段及blob转成varchar2
    闭包
    some of the properties associated with the solution could not be read解决方法
    Visual Studio 2010如何利用宏
    中高级程序员成长必备素质
    WORD小技巧
    de4dot 用法
    JavaScript学习记录
  • 原文地址:https://www.cnblogs.com/dzcici/p/9607868.html
Copyright © 2011-2022 走看看