@@ -12,6 +12,8 @@ import (
12
12
"strconv"
13
13
"strings"
14
14
15
+ "github.com/go-sql-driver/mysql"
16
+
15
17
tcontext "github.com/pingcap/dumpling/v4/context"
16
18
17
19
"github.com/pingcap/errors"
@@ -49,6 +51,13 @@ func ShowCreateDatabase(db *sql.Conn, database string) (string, error) {
49
51
}
50
52
query := fmt .Sprintf ("SHOW CREATE DATABASE `%s`" , escapeString (database ))
51
53
err := simpleQuery (db , query , handleOneRow )
54
+ if mysqlErr , ok := errors .Cause (err ).(* mysql.MySQLError ); ok {
55
+ // Falling back to simple create statement for MemSQL/SingleStore, because of this:
56
+ // ERROR 1706 (HY000): Feature 'SHOW CREATE DATABASE' is not supported by MemSQL.
57
+ if mysqlErr .Number == 1706 {
58
+ return fmt .Sprintf ("CREATE DATABASE `%s`" , escapeString (database )), nil
59
+ }
60
+ }
52
61
if err != nil {
53
62
return "" , errors .Annotatef (err , "sql: %s" , query )
54
63
}
@@ -642,7 +651,14 @@ func createConnWithConsistency(ctx context.Context, db *sql.DB) (*sql.Conn, erro
642
651
query = "START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */"
643
652
_ , err = conn .ExecContext (ctx , query )
644
653
if err != nil {
645
- return nil , errors .Annotatef (err , "sql: %s" , query )
654
+ // Some MySQL Compatible databases like Vitess and MemSQL/SingleStore
655
+ // are newer than 4.1.8 (the version comment) but don't actually support
656
+ // `WITH CONSISTENT SNAPSHOT`. So retry without that if the statement fails.
657
+ query = "START TRANSACTION"
658
+ _ , err = conn .ExecContext (ctx , query )
659
+ if err != nil {
660
+ return nil , errors .Annotatef (err , "sql: %s" , query )
661
+ }
646
662
}
647
663
return conn , nil
648
664
}
0 commit comments