46

I am trying to use mysql -u root -p Tutorials < tut_backup.sql in PowerShell to restore a table in a MySQL DB but it's giving me The '<' operator is reserved for future use. error. Is there a roundabout way?

Concerned_Citizen
  • 6,548
  • 18
  • 57
  • 75
  • 3
    [Similar Question](http://stackoverflow.com/questions/2148746/the-operator-is-reserved-for-future-use-powershell) – E.V.I.L. Apr 03 '13 at 00:44
  • Possible duplicate of [The '<' operator is reserved for future use](https://stackoverflow.com/questions/2148746/the-operator-is-reserved-for-future-use) – Inanc Gumus Sep 26 '18 at 00:05

3 Answers3

62

How about

& cmd.exe /c "mysql -u root -p Tutorials < tut_backup.sql" 
Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Jackie
  • 2,476
  • 17
  • 20
21

You can pipe in the contents like so:

Get-Content tut_backup.sql | mysql -u root -p Tutorials
Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Dean Or
  • 2,822
  • 2
  • 26
  • 25
  • 1
    This saved me. Just dropping a comment because this answer helped me multiple times. – Ananta K Roy Sep 01 '20 at 12:40
  • 1
    Works, at least for smaller files. But reads the entire file into memory, making larger files a no go (Program 'mysql.exe' failed to run: The capacity was less than the current size) – Tor Claesson Sep 01 '22 at 07:38
9

Try this instead:

mysql -u root -p
(prompts for password)
source tut_backup.sql
  • mysql is the MySQL Command-Line Client
  • -u root is the MySQL user name to use when connecting to server
  • -p is the password to use when connecting to server. It's recommended to leave blank, and enter after the MySQL prompts for password, so your password doesn't leak to the PowerShell history file.
  • for more options, such as a custom port, see mysql Client Options in the official documentation.
  • source is a command to execute an SQL script file. It takes a file name as an argument.
  • for more commands, such as "How do I exit Vim MySQL?", visit mysql Client Commands page in the official documentation.

Credit for the idea to use mysql cli with source command goes to wallyk.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259