44
55namespace Drush \Sql ;
66
7+ use Consolidation \SiteProcess \Util \Escape ;
78use Drush \Drush ;
89use Drush \Exec \ExecTrait ;
910use PDO ;
@@ -21,11 +22,26 @@ class SqlMysql extends SqlBase
2122 */
2223 public static function make (array $ dbSpec , array $ options ): SqlMysql |SqlMariaDB
2324 {
24- // If the mysql version reports that it is MariaDB, use MariaDB as client.
25- $ process = Drush::shell ('mysql --version ' );
25+ $ process = Drush::shell (Escape::isWindows () ? 'where mysql ' : 'command -v mysql ' );
2626 $ process ->setSimulated (false );
2727 $ process ->run ();
28- if ((!$ process ->isSuccessful () || str_contains ($ process ->getOutput (), 'MariaDB ' )) && self ::programExists ('mariadb ' ) && self ::programExists ('mariadb-dump ' )) {
28+ if ($ process ->isSuccessful ()) {
29+ $ clientPath = $ process ->getOutput ();
30+ // The mysql client might be symlinked to a mariadb client.
31+ // For example see https://pkgs.alpinelinux.org/package/edge/main/x86/mysql-client
32+ if (is_link ($ clientPath )) {
33+ $ clientPath = readlink ($ clientPath ) ?: throw new \Exception ('Failed to read symlink ' . $ clientPath );
34+ }
35+ $ client = basename ($ clientPath );
36+ }
37+ elseif (self ::programExists ('mariadb ' )) {
38+ $ client = 'mariadb ' ;
39+ }
40+ else {
41+ throw new \Exception ('Failed to locate mysql client ' );
42+ }
43+
44+ if ($ client === 'mariadb ' ) {
2945 $ instance = new SqlMariaDB ($ dbSpec , $ options );
3046 } else {
3147 $ instance = new self ($ dbSpec , $ options );
@@ -115,7 +131,6 @@ public function creds($hide_password = true): string
115131 'ssl_cert ' => (defined ('Pdo\Mysql::ATTR_SSL_CA ' ) ? Pdo \Mysql::ATTR_SSL_CERT : PDO ::MYSQL_ATTR_SSL_CERT ),
116132 'ssl_cipher ' => (defined ('Pdo\Mysql::ATTR_SSL_CA ' ) ? Pdo \Mysql::ATTR_SSL_CIPHER : PDO ::MYSQL_ATTR_SSL_CIPHER ),
117133 'ssl_key ' => (defined ('Pdo\Mysql::ATTR_SSL_CA ' ) ? Pdo \Mysql::ATTR_SSL_KEY : PDO ::MYSQL_ATTR_SSL_KEY ),
118- 'ssl_verify_server_cert ' => (defined ('Pdo\Mysql::ATTR_SSL_CA ' ) ? Pdo \Mysql::ATTR_SSL_VERIFY_SERVER_CERT : PDO ::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT ),
119134 ];
120135
121136 if (!empty ($ dbSpec ['pdo ' ][$ attribs ['ssl_ca ' ]])) {
@@ -138,10 +153,6 @@ public function creds($hide_password = true): string
138153 $ parameters ['ssl-key ' ] = $ dbSpec ['pdo ' ][$ attribs ['ssl_key ' ]];
139154 }
140155
141- if (!empty ($ dbSpec ['pdo ' ][$ attribs ['ssl_verify_server_cert ' ]])) {
142- $ parameters ['ssl-verify-server-cert ' ] = $ dbSpec ['pdo ' ][$ attribs ['ssl_verify_server_cert ' ]];
143- }
144-
145156 return $ this ->paramsToOptions ($ parameters );
146157 }
147158
0 commit comments