mysql cli crashes if --defaults-extra-file and port is given. Move host and port parameters to --defaults-extra-file
sql-query: SELECT 1; [0.28 sec, 7.2 MB] [notice]
Executing: mysql --defaults-extra-file=/tmp/drush_Av3Ykw --database=love_drupal --host=127.0.0.1 --port=3307 --silent < /tmp/drush_pWXzpm > /dev/null
sql-query: DROP DATABASE IF EXISTS love_drupal; CREATE DATABASE [notice]
love_drupal /*!40100 DEFAULT CHARACTER SET utf8 */; [0.33 sec, 7.21
Executing: mysql --defaults-extra-file=/tmp/drush_fulXsQ --database=information_schema --host=127.0.0.1 --port=3307 --silent < /tmp/drush_TWwWoG
ERROR 1045 (28000): Access denied for user 'love'@'localhost' (using password: YES)
Failed to create database: ERROR 1045 (28000): Access denied for user [error]
'love'@'localhost' (using password: YES) [0.38 sec, 7.21 MB]
My mysql version is: mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
which is below the minimal requirement for D8, however, the DB I am actually using is MariaDB 10.0.
Notice that the following command, exectuted from the command line, works:
mysql --defaults-extra-file=~/.my.mariadb.cnf --database=information_schema --host=127.0.0.1
while the following does not:
[love@arcturus ~]$ mysql --defaults-extra-file=~/.my.mariadb.cnf --database=information_schema --host=127.0.0.1 --port=3307
ERROR 1045 (28000): Access denied for user 'love'@'localhost' (using password: YES)
My Solution
I had a look at drush/src/Sql/SqlMysql.php
(see) and changed the generated file to include the port number:
#This file was written by Drush's Sqlmysql.php.
[client]
user="{$dbSpec['username']}"
password="{$dbSpec['password']}"
host="{$dbSpec['host']}"
port="{$dbSpec['port']}"
Since I am using a different version than the linked version above I wrote:
#This file was written by Drush's Sqlmysql.php.
[client]
user="{$this->db_spec['username']}"
password="{$this->db_spec['password']}"
host="{$this->db_spec['host']}"
port="{$this->db_spec['port']}"
in drupal/vendor/drush/drush/lib/Drush/Sql/Sqlmysql.php
. composer lists my drush as:
"name": "drush/drush",
"version": "8.1.13",
"source": {
"type": "git",
"url": "https://github.com/drush-ops/drush.git",
"reference": "f93fc2bed05ba58cf65fb65f799429bf6354b205"
Then I commented the setting of host
and port
as command line arguments.
// EMPTY host is not the same as NO host, and is valid (see unix_socket).
elseif (isset($this->db_spec['host'])) {
//$parameters['host'] = $this->db_spec['host'];
if (!empty($this->db_spec['port'])) {
//$parameters['port'] = $this->db_spec['port'];
and it worked. However, the database is now love_drupal
and not information_schema
anymore.