描述中给出的代码可以在Windows系统中执行吗?
给出的代码可以在Windows系统中执行吗?好像是Linux命令
echo 'create database foo2' | mysql -uroot
mysqldump --skip-triggers -uroot foo | mysql -uroot foo2
已编辑 我正在执行以下代码,但没有得到我所期望的结果..
<?php
mysql_connect('localhost','root','********');
echo 'create database pranav_chk'. | mysql -u root
mysqldump --skip-triggers -u root pranav_test | mysql -u root pranav_chk;
?>
is the code given is executable in Windows system? as it seems to be Linux commands
echo 'create database foo2' | mysql -uroot
mysqldump --skip-triggers -uroot foo | mysql -uroot foo2
EDITED
I am executing the following code but I am not getting what I expect..
<?php
mysql_connect('localhost','root','********');
echo 'create database pranav_chk'. | mysql -u root
mysqldump --skip-triggers -u root pranav_test | mysql -u root pranav_chk;
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该代码使用三个命令行功能:
echo
命令|
符号)连接命令mysql
命令行客户端这三个功能都是在 Windows 和 Linux 上可用并且工作方式相同(就此处使用的程度而言),因此代码实际上是可移植的。
编辑:代码需要在shell中运行,不能只是将其放入PHP脚本中。你必须使用
exec()
之类的东西像这样:但是,之前的
mysql_connect()
调用不会给你带来任何好处,因为它只对 PHP 脚本有效。您必须直接通过命令行进行身份验证。或者,您可以使用它和mysql_create_db()< /code>
替换第一行
exec()
行。The code uses three command-line features:
echo
command|
symbol)mysql
command line clientAll three are available and work identically (to the degree they're used here) on Windows and on Linux, so the code is in fact portable.
Edit: The code needs to be run in the shell, you can't just put it into a PHP script. You have to use
exec()
, something like this:However, the
mysql_connect()
call before won't do you any good, because it's only valid for the PHP script. You'll have to do authentication via the command line directly. Alternatively, you could use it andmysql_create_db()
to replace the firstexec()
line.它应该可以工作,假设 mysql 和 mysqldump 位于 Windows PATH 变量中。尽管您应该在 -u 和根目录之间添加一个空格。
It should work yes, assuming mysql and mysqldump are in the windows PATH variable. Although you should add a space between the -u and the root.
3 笔记。
首先,PHP 脚本中的数据库连接不与外部系统命令共享。
其次,您需要向命令行提供密码。
三、使用 exec 函数运行命令。
例如:
未经测试,但这是总体思路。
3 notes.
First, the database connection in the PHP script is not shared with the outside system command.
Second, you need to supply password to the command line.
Three, use the exec function to run your command.
For example:
Not tested but thats the general idea.