Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
二、操作
1. 连接数据库
2. 创建数据库
3. 常用 SQL
# 登录容器。dockerexec-it['容器ID'] /opt/mssql-tools/bin/sqlcmd \-S localhost -U sa -P['密码']dockerexec-it'sqlserver_1' /opt/mssql-tools/bin/sqlcmd \-S localhost -U sa -P'AAAbbb123'# 还原数据库。sudodockerexec-it'sqlserver_1' /opt/mssql-tools/bin/sqlcmd \-S localhost -U SA -P'AAAbbb123'\-Q'RESTORE DATABASE test FROM DISK = "/var/opt/mssql/test.bak" WITH MOVE "test" TO "/var/opt/mssql/data/test.mdf", MOVE "test_log" TO "/var/opt/mssql/data/test.ldf"'sudodockerexec-it'sqlserver_2019' /opt/mssql-tools/bin/sqlcmd
-S localhost \-U SA \-P'AAAbbb123'\-Q'RESTORE FILELISTONLY FROM DISK = "/var/opt/mssql/rs.bak"'\|tr-s' '|cut-d' '-f1-2
-- 查看数据库连接数。SELECTCOUNT(1)FROM[Master].[dbo].[SYSPROCESSES]WHERE[DBID]IN(SELECT[DBID]FROM[Master].[dbo].[SYSDATABASES]WHERE NAME='库名')
go
------------------------------------------------------------select*from sysprocesses
where dbid in(select dbid from sysdatabases where name='库名')
go
------------------------------------------------------------SELECT u.id, u.name
FROM[test].[dbo].[user] u
go