从命令提示符窗口执行 MySql
我想从命令行执行 sql 查询(存储在文本文件中)。
从我发现的情况来看,我可以看到这应该有效:
mysql -u root -p < create_database.sql
当我尝试执行此操作并希望帮助理解时出现错误。
root 可以保留 root,对吗?或者我是否必须指定我的用户名来代替单词 root?我认为 -u 会提示我输入用户名,而 -p 会在输入上述内容后提示我输入密码,但我不确定,因为我是从命令行运行的初学者。
另外,我是否必须位于该文件所在的目录中才能正常工作?我不这么认为,因为它被重定向到特定文件...
提前感谢您的帮助:)
I want to execute an sql query (stored in a text file) from the command line.
From what I have found, I can see that this should work:
mysql -u root -p < create_database.sql
I get an error when I try to do this and wanted help understanding.
Root can remain root, correct? Or do I have to specify my username in place of the word root? I thought that -u would prompt me for my username and -p would prompt me for a password after the above was typed in, but I'm not sure as I'm a beginner at running from the command line.
Also, do I have to be in the directory of where this file is located for this to work? I wouldn't think so since it is being redirected to the specific file...
Thank you in advance for any help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实应该在 -u 后面加上您的用户名,而不是在 root 下创建数据库,并且使用文件的完整路径或导航到它所在的目录。
您可能需要登录并使用 source 命令。
You should really follow -u with your username rather than creating databases under root, and either use the full path to the file or navigate to the directory it's in.
You might want to log in and use the source command.