描述中给出的代码可以在Windows系统中执行吗?

发布于 2024-08-31 04:54:29 字数 475 浏览 4 评论 0原文

给出的代码可以在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

拥有 2024-09-07 04:54:29

该代码使用三个命令行功能:

  • echo 命令
  • 通过管道(| 符号)连接命令
  • mysql 命令行客户端

这三个功能都是在 Windows 和 Linux 上可用并且工作方式相同(就此处使用的程度而言),因此代码实际上是可移植的。

编辑:代码需要在shell中运行,不能只是将其放入PHP脚本中。你必须使用 exec() 之类的东西像这样:

<?php
  exec("echo 'create database foo2' | mysql -uroot");
  exec("mysqldump --skip-triggers -uroot foo | mysql -uroot foo2");
?>

但是,之前的 mysql_connect() 调用不会给你带来任何好处,因为它只对 PHP 脚本有效。您必须直接通过命令行进行身份验证。或者,您可以使用它和 mysql_create_db()< /code>替换第一行 exec() 行。

The code uses three command-line features:

  • An echo command
  • Connecting commands via pipes (the | symbol)
  • The mysql command line client

All 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:

<?php
  exec("echo 'create database foo2' | mysql -uroot");
  exec("mysqldump --skip-triggers -uroot foo | mysql -uroot foo2");
?>

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 and mysql_create_db() to replace the first exec() line.

少女情怀诗 2024-09-07 04:54:29

它应该可以工作,假设 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.

熊抱啵儿 2024-09-07 04:54:29

3 笔记。

首先,PHP 脚本中的数据库连接不与外部系统命令共享。

其次,您需要向命令行提供密码。

三、使用 exec 函数运行命令。

例如:

<?php
$PASSWORD="YOURPASSWORD";
exec("echo 'create database foo2' | mysql -u root -p $PASSWORD");
?>

未经测试,但这是总体思路。

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:

<?php
$PASSWORD="YOURPASSWORD";
exec("echo 'create database foo2' | mysql -u root -p $PASSWORD");
?>

Not tested but thats the general idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文