MariaDB Connector/J testing with TiDB v5.2.0 and Jython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/jython | |
import sys | |
import java.util.Properties | |
import java.sql.SQLException | |
import org.mariadb.jdbc.Driver | |
# Test user setup: | |
# | |
# mysql-sql> create user 'test_native'@'%' identified with 'mysql_native_password' by 'test'; | |
# Query OK, 0 rows affected (0.0778 sec) | |
# mysql-sql> create user 'test_sha2'@'%' identified with 'caching_sha2_password' by 'test'; | |
# Query OK, 0 rows affected (0.0346 sec) | |
# mysql-sql> grant select on test.* to 'test_native'@'%'; | |
# Query OK, 0 rows affected (0.0457 sec) | |
# mysql-sql> grant select on test.* to 'test_sha2'@'%'; | |
# Query OK, 0 rows affected (0.0358 sec) | |
# export CLASSPATH=/path/to/mariadb-java-client-X.Y.Z.jar | |
for user in ["test_native", "test_sha2"]: | |
for ssl in ["false", "true"]: | |
drv = org.mariadb.jdbc.Driver() | |
p = java.util.Properties() | |
driverName = "{} v{}.{}".format( | |
drv.getClass().canonicalName, drv.majorVersion, drv.minorVersion | |
) | |
jdbc_url = "jdbc:mariadb://127.0.0.1:4000/test?user={}&password=test&useSSL={}&trustServerCertificate=true".format( | |
user, ssl | |
) | |
print("======================================================") | |
try: | |
conn = drv.connect(jdbc_url, p) | |
stmt = conn.prepareStatement( | |
'SELECT CONNECTION_ID() AS "connid", VERSION() AS "version"' | |
) | |
res = stmt.executeQuery() | |
while res.next(): | |
print( | |
"connection {} to TiDB {}".format( | |
res.getString("connid"), res.getString("version") | |
) | |
) | |
print("%s %s\nSuccess: %s" % (driverName, jdbc_url, conn)) | |
except java.sql.SQLException as e: | |
print("%s %s\nFailed: %s" % (driverName, jdbc_url, e)) | |
print("======================================================") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So looks like
mysql_native_password
works in all situations, butcaching_sha2_password
only works with MariaDB Connector/J 2.7.4 on a TLS connection.