0

I want to write SQL queries in a PowerShell script to run them with Task Scheduler later.

$db   = 'hotels'
$user = 'root'
$pass = ''

$mysql  = 'C:\mariadb\mariadb-10.3.12-winx64\bin\mysql.exe'
$params = '-u', $user, $db

& $mysql @params -e 'SELECT user FROM ondemandscheduledrequests ORDER BY id DESC LIMIT 1' hotels

Start-Sleep -Seconds 10

I tried a simple one like this.

When I performed a SELECT * query it worked fine, but when I try to retrieve a single field, I have this displayed:

mysql.exe output

I don't understand why it is not working.

3
  • 4
    what is that hotels at the end ? Commented Jun 13, 2019 at 10:12
  • The spurious trailing "hotels" aside, using the commandline utility is not recommended. Please see the latter half of my answer here. Commented Jun 13, 2019 at 11:35
  • it is the name of my table Commented Jun 13, 2019 at 12:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.