我正在Microsoft SQL Server on Linux for Docker Engine中本地运行数据库,我可以使用mssql-cli -U username -P password -d dbname
成功连接到数据库,但是我正在努力使用SchemaSpy连接到数据库,例如
$ java -jar schemaspy-6.0.0.jar -t mssql -u username -p password -o . -host localhost -port 1433 -db dbname
INFO - Started Main in 1.183 seconds (JVM running for 1.556)
INFO - Configuration file not found
INFO - Starting schema analysis
INFO - Failed to validate png renderer ':cairo'. Reverting to default renderer for png.
WARN - Connection Failure
您知道我该如何解决连接故障吗?
答案 0 :(得分:1)
我以此启动SQL Server:
docker run --name sqlserver -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=BadPassword1' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest-ubuntu
我会检查您是否为Docker桌面提供了足够的RAM。当我第一次使用配置为<2GB RAM的Docker启动SQL Server时,该容器启动了,但是当我查看日志时,我无法连接:
docker logs sqlserver
(sqlserver是退出的Docker容器的名称)
我看到了:
sqlservr: This program requires a machine with at least 2000 megabytes of memory.
/opt/mssql/bin/sqlservr: This program requires a machine with at least 2000 megabytes of memory.
一旦我将Docker桌面更新为再次具有2GB的RAM(不久前将其降至1GB),它就正常了。
一个启动,我可以使用nmap localhost -p 1433
来验证端口是否打开。
然后我通过在正在运行的容器上启动一个交互式外壳程序来检查SQL Server是否正在运行:
docker exec -it --rm sqlserver /bin/bash
在交互式外壳程序内部,我可以使用/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P BadPassword1
访问SQL Server外壳程序。在mssql shell中,您必须键入所需的内容,然后在单独的行上输入GO
以执行您输入的所有内容。
因此,要列出数据库:
SELECT name FROM master.sys.databases;
GO
列出表格:
SELECT DISTINCT TABLE_NAME FROM information_schema.TABLES;
GO
然后我创建了一个数据库和一个表来针对以下对象运行SchemaSpy:
CREATE DATABASE SchemaSpyTest;
GO;
USE SchemaSpyTest;
GO;
CREATE TABLE TableTest1(id int);
GO
然后,我运行了您在SchemaSpy上列出的参数,它对我也不起作用。
使用-debug标志后,我发现mssql
设置还不够:
org.schemaspy.model.ConnectionFailure: Failed to connect to database URL [jdbc:microsoft:sqlserver://localhost:1433;databaseName=dbname] Failed to create any of 'com.microsoft.sqlserver.jdbc.SQLServerDriver, com.microsoft.jdbc.sqlserver.SQLServerDriver' driver from driverPath 'C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msbase.jar;C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/mssqlserver.jar;C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msutil.jar' with sibling jars no.
Resulting in classpath: empty
There were missing paths in driverPath:
C
/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msbase.jar;C
/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/mssqlserver.jar;C
/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msutil.jar
Use commandline option '-dp' to specify driver location.
If you need to load sibling jars used '-loadjars'
at org.schemaspy.DbDriverLoader.getConnection(DbDriverLoader.java:101)
at org.schemaspy.DbDriverLoader.getConnection(DbDriverLoader.java:75)
at org.schemaspy.service.SqlService.connect(SqlService.java:68)
at org.schemaspy.SchemaAnalyzer.analyze(SchemaAnalyzer.java:186)
at org.schemaspy.SchemaAnalyzer.analyze(SchemaAnalyzer.java:107)
at org.schemaspy.cli.SchemaSpyRunner.runAnalyzer(SchemaSpyRunner.java:97)
at org.schemaspy.cli.SchemaSpyRunner.run(SchemaSpyRunner.java:86)
at org.schemaspy.Main.main(Main.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
因此,我从https://www.microsoft.com/en-us/download/details.aspx?id=57782下载了JDBC驱动程序,并将其与其他脚本保存在同一文件夹中。
然后,我能够根据文档计算出正确的参数组合:
java -jar schemaspy-6.0.0.jar -t mssql05 -u sa -p BadPassword1 -o . -host localhost -port 1433 -db SchemaSpyTest -debug -dp ./sqljdbc_7.2/enu/mssql-jdbc-7.2.2.jre8.jar
dp标志链接到Microsoft SQL Server JDBC驱动程序中的JAR文件。
之后,它运行良好。