很明显,shell 脚本正在等待 Y/N 响应,而不是 MySQL 客户端。
您应该可以通过复制/粘贴直接执行该行
mysql -uuser -ppass -e "DROP DATABASE IF EXISTS database"
在 Linux 命令提示符处。
如果您愿意,在此命令出现的位置,只需将 shell 脚本中的 Y/N 响应注释掉即可。
我的下一个建议是让您查看您的 my.cnf。
查看是否有 [mysql] 或 [client] 部分包含以下内容:
[mysql]
i-am-a-dummy
safe-updates
或
[client]
i-am-a-dummy
safe-updates
这些是真正的选择:请参阅 MySQL 文档中的 safe-updates and i-am-a-dummy
更新 2013-01-25 16:48 EDT
我的下一个猜测是操作系统。为什么???
如果您以root 身份登录Linux 或执行sudo,则您毫无疑问地有权执行DROP DATABASE IF EXISTS。在操作系统级别,mysqld 会尝试丢弃数据库的文件夹。
例如,如果datadir是/var/lib/mysql并且你执行DROp DATABASE IF EXISTS rolando;,mysqld会尝试运行rm -rf /var/lib/mysql/rolando。
如果您不是root 或sudo,则不是root,我希望操作系统会回显该消息。事实上,当我没有以 root 身份登录并尝试 service mysql stop 时,我已经看到来自操作系统的消息要求删除 PID 文件。
更新 2013-01-25 16:54 EDT
mysqladmin 也不会引起提示,除了密码。以下是它的所有选项:
[root@***]# mysqladmin --help
mysqladmin Ver 8.42 Distrib 5.1.47, for redhat-linux-gnu on x86_64
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Administration program for the mysqld daemon.
Usage: mysqladmin [OPTIONS] command command....
-c, --count=# Number of iterations to make. This works with -i
(--sleep) only.
--debug-check Check memory and open file usage at exit.
--debug-info Print some debug info at exit.
-f, --force Don't ask for confirmation on drop database; with
multiple commands, continue even if an error occurs.
-C, --compress Use compression in server/client protocol.
--character-sets-dir=name
Directory for character set files.
--default-character-set=name
Set the default character set.
-?, --help Display this help and exit.
-h, --host=name Connect to host.
-b, --no-beep Turn off beep on error.
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's asked from the tty.
-P, --port=# Port number to use for connection or 0 for default to, in
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/services, built-in default (3306).
--protocol=name The protocol to use for connection (tcp, socket, pipe,
memory).
-r, --relative Show difference between current and previous values when
used with -i. Currently only works with extended-status.
-O, --set-variable=name
Change the value of a variable. Please note that this
option is deprecated; you can set variables directly with
--variable-name=value.
-s, --silent Silently exit if one can't connect to server.
-S, --socket=name The socket file to use for connection.
-i, --sleep=# Execute commands repeatedly with a sleep between.
--ssl Enable SSL for connection (automatically enabled with
other flags). Disable with --skip-ssl.
--ssl-ca=name CA file in PEM format (check OpenSSL docs, implies
--ssl).
--ssl-capath=name CA directory (check OpenSSL docs, implies --ssl).
--ssl-cert=name X509 cert in PEM format (implies --ssl).
--ssl-cipher=name SSL cipher to use (implies --ssl).
--ssl-key=name X509 key in PEM format (implies --ssl).
--ssl-verify-server-cert
Verify server's "Common Name" in its cert against
hostname used when connecting. This option is disabled by
default.
-u, --user=name User for login if not current user.
-v, --verbose Write more information.
-V, --version Output version information and exit.
-E, --vertical Print output vertically. Is similar to --relative, but
prints output vertically.
-w, --wait[=#] Wait and retry if connection is down.
--connect_timeout=#
--shutdown_timeout=#
嘿,我说得对
--force 提示 DROP DATABASE
好吧,我猜你找到了罪魁祸首。我今天学到了一些东西,因为我不使用mysqladmin 来删除数据库。