如何删除Docker容器内的SQL Server数据库?

时间:2023-01-12 07:24:38

Long time no post! My question is as the title says - how to delete a SQL Server database inside a docker container.

很久没有帖子了!我的问题是标题所示 - 如何删除docker容器中的SQL Server数据库。

Scenario: I am on a MacBook Pro running macOS High Sierra 10.13.4 running Docker 18.03.0-ce-mac60 (23751)

场景:我在MacBook Pro上运行macOS High Sierra 10.13.4运行Docker 18.03.0-ce-mac60(23751)

I followed the instructions to set up SQL Server 2017 inside a Docker container at the following link (Setting up SQL Server in Docker on a Mac) and now have a database running.

我按照说明在以下链接的Docker容器中设置SQL Server 2017(在Mac上的Docker中设置SQL Server),现在运行数据库。

But now I want to delete the database and rebuild it again. I don't really care for the data inside it, I just want to get rid of the database without necessary deleting the container and just create a new DB using the SQL Server instance.

但现在我想删除数据库并重新生成它。我并不真正关心其中的数据,我只是想摆脱数据库而不必删除容器,只需使用SQL Server实例创建一个新的数据库。

I am aware that it may involve using the sqlcmd tool from within Docker, but I am unsure of the particular parameters required, and I cannot find much information on the process otherwise..

我知道它可能涉及在Docker中使用sqlcmd工具,但我不确定所需的特定参数,否则我找不到有关该过程的更多信息。

Thanks in advance!

提前致谢!

2 个解决方案

#1


1  

Assuming that you followed the guide exactly as it is -

假设您完全按原样遵循指南 -

  1. Open a new terminal in your container:
  2. 在容器中打开一个新终端:

Using bash:

sudo docker exec -it sql1 "bash"

OR PowerShell

docker exec -it sql1 "bash"
  1. Connect to sqlcmd using your original query:
  2. 使用原始查询连接到sqlcmd:

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '<YourNewStrong!Passw0rd>'
  1. Next run the command to drop/delete your database:
  2. 接下来运行命令以删除/删除数据库:

DROP DATABASE TestDB;
  1. Commit your changes:
  2. 提交您的更改:

GO;

#2


0  

Have you tried following article to delete your database:

您是否尝试过以下文章来删除数据库:

USE master ;  
GO  
DROP DATABASE Sales, NewSales ;  
GO

#1


1  

Assuming that you followed the guide exactly as it is -

假设您完全按原样遵循指南 -

  1. Open a new terminal in your container:
  2. 在容器中打开一个新终端:

Using bash:

sudo docker exec -it sql1 "bash"

OR PowerShell

docker exec -it sql1 "bash"
  1. Connect to sqlcmd using your original query:
  2. 使用原始查询连接到sqlcmd:

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '<YourNewStrong!Passw0rd>'
  1. Next run the command to drop/delete your database:
  2. 接下来运行命令以删除/删除数据库:

DROP DATABASE TestDB;
  1. Commit your changes:
  2. 提交您的更改:

GO;

#2


0  

Have you tried following article to delete your database:

您是否尝试过以下文章来删除数据库:

USE master ;  
GO  
DROP DATABASE Sales, NewSales ;  
GO