如何在命令行中的数据库上运行脚本(MySQL 服务器)
我刚刚安装了 MySQL 社区服务器,现在想要创建一个数据库,然后在命令行中运行一个脚本。
我尝试了这个,但看起来不起作用:
CREATE DATABASE admin_web_projektu
mysql admin_web_projektu < c:/USI-4/db_template_001.sql
I have just installed MySQL Community Server and now want to create a database and then run a script on it in a command line.
I tried this one but looks like it doesn't work:
CREATE DATABASE admin_web_projektu
mysql admin_web_projektu < c:/USI-4/db_template_001.sql
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用以下步骤:
创建数据库
yourdbname;使用
yourdbname;源
path_to_DB_script;use below steps:
Create database
yourdbname;use
yourdbname;source
path_to_DB_script;试试这个:
参考文献:阅读此内容以获取更多详细信息 http:// /docs.oracle.com/cd/E17952_01/refman-5.1-en/load-data.html
try this:
References: read this for more detail http://docs.oracle.com/cd/E17952_01/refman-5.1-en/load-data.html
您需要退出 MySQL 控制台才能运行命令。
-u
表示用户,-p
运算符表示密码,-B
表示要使用的数据库。注意-p
和密码之间不能有空格,否则MySQL会认为密码的空格部分。我也倾向于在用户名前留下一个空格:)我猜是老习惯了。大于和小于运算符
<
和>
充当 bash 命令的方向指示符。将它们视为“进入”。因此,上面的语句可以表述如下:如果您将数据库转储到文件中,则您的方向将是
>
朝向该文件。但是,您希望将文件“放入”数据库,因此方向为<
。也许这有帮助?You need to exit the MySQL console to run your command.
The
-u
indicates user,-p
operator indicates the password and-B
the database to use. Note that there is no gap between the-p
and the password, otherwise MySQL considers the space part of the password. I tend to leave out a space before the username too :) old habits I guess.The greater and less than operators
<
and>
act as directional indicators for your bash commands. Think of them as 'into'. So the above statement might be stated as follows:If you were dumping the database into a file, your direction would be
>
toward the file. However, you want to put the file 'into' the database, so the direction is<
. Maybe that helps?