Linux 如何通过shell命令删除mysql数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2050581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete mysql database through shell command
提问by
I use the pylons and sqlalchemy. I constantly update the schema files and delete and recreate the database so that new schema can be made.
我使用 pylons 和 sqlalchemy。我不断更新架构文件并删除并重新创建数据库,以便可以创建新架构。
Every time I do this by opening the MySql Query Browser and login and delete the database/schema.
每次我通过打开 MySql 查询浏览器并登录和删除数据库/模式来执行此操作。
How do I delete the MySQL db/schema thorough linux shell commands in Ubuntu Linux?
如何在 Ubuntu Linux 中删除 MySQL db/schema 彻底的 linux shell 命令?
采纳答案by Alex Reisner
Try the following command:
尝试以下命令:
mysqladmin -h[hostname/localhost] -u[username] -p[password] drop [database]
回答by gahooa
Another suitable way:
另一种合适的方式:
$ mysql -u you -p
<enter password>
>>> DROP DATABASE foo;
回答by gahooa
If you are tired of typing your password, create a (chmod 600) file ~/.my.cnf
, and put in it:
如果您厌倦了输入密码,请创建一个 (chmod 600) 文件~/.my.cnf
,然后放入:
[client]
user = "you"
password = "your-password"
For the sake of conversation:
为了对话:
echo 'DROP DATABASE foo;' | mysql
回答by Yada
In general, you can pass any query to mysql
from shell with -e option.
通常,您可以mysql
使用 -e 选项将任何查询传递给来自 shell。
mysql -u username -p -D dbname -e "DROP DATABASE dbname"
回答by engineerDave
No need for mysqladmin:
不需要 mysqladmin:
just use mysql command line
只需使用 mysql 命令行
mysql -u [username] -p[password] -e 'drop database db-name;'
This will send the drop command although I wouldn't pass the password this way as it'll be exposed to other users of the system via ps aux
这将发送 drop 命令,尽管我不会以这种方式传递密码,因为它会通过ps aux暴露给系统的其他用户
回答by iyad
[root@host]# mysqladmin -u root -p drop [DB]
Enter password:******
回答by Ilija
MySQL has discontinued drop database command from mysql client shell. Need to use mysqladmin to drop a database.
MySQL 已停止从 mysql 客户端 shell 执行 drop database 命令。需要使用 mysqladmin 删除数据库。
回答by Bhautik Nada
You can remove database directly as:
您可以直接删除数据库:
$ mysqladmin -h [host]-u [user]-p drop [database_name]
$ mysqladmin -h [host]-u [user]-p drop [database_name]
[Enter Password]
[输入密码]
Do you really want to drop the 'hairfree' database [y/N]: y
你真的想删除'hairfree'数据库吗[y/N]: y