mysql - 将 MYSQL 行导出到多个 txt 文件中

标签 mysql select

我有一个包含 50.000 行的 MYSQL 数据库。每行代表一篇文章。我希望将名称为“articletext”的列的值拆分为 50.000 个文件。每一行一个文件。我是 MYSQL 新手,所以我不知道如何执行此操作。

有人可以帮助我吗?

谢谢

最佳答案

我创建了这个小型java应用程序来解决这个问题。

        try {
        Class.forName("com.mysql.jdbc.Driver");
        System.out.println("Opening connection");
        Connection con = DriverManager.getConnection(
                "jdbc:mysql://localhost/articles", "username", "password");

        String query = "Select title,articletext from articles";

        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {
            String title = rs.getString(1);
            String text = rs.getString(2);

            try {
                FileWriter fstream = new FileWriter(title + ".txt");

                BufferedWriter out = new BufferedWriter(fstream);
                out.write(text);
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

        System.out.println("Closing connection");
        con.close();

    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

关于mysql - 将 MYSQL 行导出到多个 txt 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9758938/

相关文章:

php - 如果崩溃如何自动修复表

php - 函数填充第一个列表框但不填充数据库表中的第二个

php - Where cell is not equal to.. MySQL查询(!=)

mysql - 如何按 MAX(日期)选择?

mysql - 如何选择具有相同外部列表(两个表)的记录?

mysql - 一个sql查询中的三个计数

php - 如何在CodeIgniter中发送id值?

mysql - 右连接查询返回不匹配的值

php - 使用 PHP 从 MySQL 获取信息时遇到问题

mysql - 从 mySQL 中的各种表中选择列