Calling MySQL exe using PHP exec doesn't work

后端 未结 6 1097
一整个雨季
一整个雨季 2020-12-20 02:52

I have an extremely simple script with PHP exec, calling mysql command:

  $dbhost = \'localhost\';
  $dbuser = \'root\';
  $dbpass          


        
6条回答
  •  醉话见心
    2020-12-20 03:30

    The problem here is probably that

    mysql < file.sql
    

    depends on a pipe operation that is facilitated by the shell. If php executes the command directly using something like the exec*() family of api calls rather than through a shell this won't work. I know that the shell actually is used on linux, but this might not be the case on windows. The manual doesn't specify exactly how the command is executed.

    Try using the -e flag and the source command instead:

    bin\mysql.exe -h localhost --user=root --password=mypass -e 'source job_create.sql'
    

    This should work regardless of the way that the command is invoked.

提交回复
热议问题