我正在尝试使用命令行上的--defaults-file选项登录mysql:
$ mysql --defaults-file ~/mycnf.cnf
但是我收到以下错误:
mysql: unknown option '--defaults-file'
但是这个选项列在帮助中:
$ mysql --help
...
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-file=# Only read default options from the given file #.
这是怎么回事?这是mysql --version
的输出$ mysql --version
mysql Ver 14.14 Distrib 5.1.69, for redhat-linux-gnu (x86_64) using readline 5.1
答案 0 :(得分:6)
我想在我面临的类似情况中为这个问题添加另一个答案。
就我而言,命令与此类似:
/path/to/mysqld_safe start --defaults-file=/path/to/my.cnf --other-options-here
和mysql会抱怨
unknown variable '--defaults-file=/path/to/my.cnf'
为了解决这个问题,我不得不放弃" start
命令,使行读取如下:
/path/to/mysqld_safe --defaults-file=/path/to/my.cnf --other-options-here
然后mysql最终会开始使用指定的配置文件。
答案 1 :(得分:5)
应该是:
mysql --defaults-file=~/mycnf.cnf
您错过了=
。
答案 2 :(得分:4)
对于我来说,问题是参数的放错位置。
--console
参数应该排在最后...
我的原始照片:
mysqld --console --defaults-file="path-to-ini/my.ini"
应该运行以下命令:
mysqld --defaults-file="path-to-ini/my.ini" --console
答案 3 :(得分:2)
要使用bash / sh脚本而不是直接在OSX的cli上解决相同的问题,我必须使用mysql.client应用程序的完整路径。
$which mysql
/usr/local/zend/mysql/bin/mysql
MySql由Zend Server安装,如下面的路径所示,并包装了mysql.client版本:
$mysql --version
/usr/local/zend/mysql/bin/mysql.client Ver 14.14 Distrib 5.5.27, for osx10.6 (i386) using readline 5.1
错误继续显示,直到我改变我的bash脚本调用mysql的方式。
自:
MYSQL=`which mysql`
...
${MYSQL} --defaults-file=/dev/stdin -e "SHOW DATABASES"
输出
$ ./import_dbs.sh
/usr/local/zend/mysql/bin/mysql.client: unknown variable 'defaults-file=/dev/stdin'
更改为:
MYSQL=/usr/local/zend/mysql/bin/mysql.client
...
${MYSQL} --defaults-file=/dev/stdin -e "SHOW DATABASES"
输出
$ ./import_dbs.sh
Database
information_schema
mysql
performance_schema
test
编辑: 我也可以在我的脚本中使用以下内容:
MYSQL=`which mysql.client`
$ which mysql.client
/usr/local/zend/mysql/bin/mysql.client
显然,调用mysql和mysql.client之间存在细微差别,这会影响能够在脚本中传递-defaults文件或OP中提到的其他变量作为第一个参数。我还没有通过shell进行测试