如何使用SQL创建文件夹

时间:2021-09-06 15:47:32

I have a SQL script which selects data from DB and stores it to files. I am unable to create a directory to store these files.

我有一个SQL脚本,它从数据库中选择数据并将其存储到文件中。我无法创建存储这些文件的目录。

I have shell script that loads the SQL file. Shell and the SQL are on separate server than MySQL db. I would prefer to create this directory using SQL as I want to avoid ssh.

我有加载SQL文件的shell脚本。 Shell和SQL位于与MySQL db不同的服务器上。我更喜欢使用SQL创建此目录,因为我想避免使用ssh。

Any suggestions? Surprisingly I couldn't find anything on Google.

有什么建议么?令人惊讶的是我在Google上找不到任何东西。

2 个解决方案

#1


1  

I will assume that you're using mysql, according to your tags. You could do it with a Microsoft SQL Server or Oracle database but unfortunately, at the moment, there is no solution to create a directory from MySQL.

根据你的标签我会假设你正在使用mysql。您可以使用Microsoft SQL Server或Oracle数据库执行此操作,但遗憾的是,目前还没有从MySQL创建目录的解决方案。

Some will guide you with a workaround based on the creation of a data directory, I wouldn't recommand this, as it could lead to performances issues in the future, or worst.

有些人会根据数据目录的创建情况为您提供解决方法,我不建议这样做,因为它可能导致未来或最糟糕的性能问题。

The best solution would be to use a script (java, vbscript, SSH, batch, ...). Again, you won't be able to start this script within your SQL query easily. I know that's no good news, but it is important not to lead you on the wrong direction.

最好的解决方案是使用脚本(java,vbscript,SSH,batch,...)。同样,您将无法轻松地在SQL查询中启动此脚本。我知道这不是好消息,但重要的是不要引导你走错方向。

I would suggest to reverse your thinking, and start your SQL query from a script (again, any language you're used to).

我建议改变你的想法,从脚本开始你的SQL查询(再次,你习惯的任何语言)。

#2


1  

I couldn't find any other way other than opening ssh session to the target box.

除了打开目标框的ssh会话之外,我找不到任何其他方法。

  1. Open ssh session
  2. 打开ssh会话
  3. Create directory
  4. 创建目录
  5. close ssh session
  6. 关闭ssh会话
  7. Load sql file using shell
  8. 使用shell加载sql文件
  9. The sql adds the generated files to the directory created in step 2.
  10. sql将生成的文件添加到步骤2中创建的目录中。
ssh -t $USER@$HOST <<-SSH-END;
  mkdir -p "dir/path";
  exit;
SSH-END

Sharing just in case someone else needs to do the same.

分享以防万一其他人需要做同样的事情。

#1


1  

I will assume that you're using mysql, according to your tags. You could do it with a Microsoft SQL Server or Oracle database but unfortunately, at the moment, there is no solution to create a directory from MySQL.

根据你的标签我会假设你正在使用mysql。您可以使用Microsoft SQL Server或Oracle数据库执行此操作,但遗憾的是,目前还没有从MySQL创建目录的解决方案。

Some will guide you with a workaround based on the creation of a data directory, I wouldn't recommand this, as it could lead to performances issues in the future, or worst.

有些人会根据数据目录的创建情况为您提供解决方法,我不建议这样做,因为它可能导致未来或最糟糕的性能问题。

The best solution would be to use a script (java, vbscript, SSH, batch, ...). Again, you won't be able to start this script within your SQL query easily. I know that's no good news, but it is important not to lead you on the wrong direction.

最好的解决方案是使用脚本(java,vbscript,SSH,batch,...)。同样,您将无法轻松地在SQL查询中启动此脚本。我知道这不是好消息,但重要的是不要引导你走错方向。

I would suggest to reverse your thinking, and start your SQL query from a script (again, any language you're used to).

我建议改变你的想法,从脚本开始你的SQL查询(再次,你习惯的任何语言)。

#2


1  

I couldn't find any other way other than opening ssh session to the target box.

除了打开目标框的ssh会话之外,我找不到任何其他方法。

  1. Open ssh session
  2. 打开ssh会话
  3. Create directory
  4. 创建目录
  5. close ssh session
  6. 关闭ssh会话
  7. Load sql file using shell
  8. 使用shell加载sql文件
  9. The sql adds the generated files to the directory created in step 2.
  10. sql将生成的文件添加到步骤2中创建的目录中。
ssh -t $USER@$HOST <<-SSH-END;
  mkdir -p "dir/path";
  exit;
SSH-END

Sharing just in case someone else needs to do the same.

分享以防万一其他人需要做同样的事情。