-3

This might be a really stupid question so apologies in advance if this upsets anyone. I'm using mysql in git bash (tried cmd as well) and can't seem to figure out how to import a sql file I exported from VS code into mysql using the command prompt.

I tried all the solutions I could find here but it keeps giving me errors like this.

mysql> SOURCE C:/Users/smuf2/Downloads/person.sql \g

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SOURCE C:/Users/s muf2/Downloads/person.sql' at line 1

mysql> SOURCE C:\Users\smuf2\Downloads\person.sql \g

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SOURCE C:\Users\s muf2\Downloads\person.sql' at line 1

mysql> winpty mysql -u root -p test < 'C:/Users/smuf2/Downloads/person.sql' \g

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'winpty mysql -u r oot -p test < 'C:/Users/smuf2/Downloads/person.sql'' at line 1

mysql> winpty mysql -u root -p test < 'C:\Users\smuf2\Downloads\person.sql' \g

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'winpty mysql -u r oot -p test < 'C:\Users\smuf2\Downloads\person.sql'' at line 1

mysql> winpty mysql -u root -p test < C:/Users/smuf2/Downloads/person.sql \g

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'winpty mysql -u r oot -p test < C:/Users/smuf2/Downloads/person.sql' at line 1

mysql> winpty mysql -u root -p test < C:\Users\smuf2\Downloads\person.sql \g

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'winpty mysql -u r oot -p test < C:\Users\smuf2\Downloads\person.sql' at line 1

mysql> mysql -u root -p test < C:/Users/smuf2/Downloads/person.sql \g

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u roo t -p test < C:/Users/smuf2/Downloads/person.sql' at line 1

mysql> mysql -u root -p test < C:\Users\smuf2\Downloads\person.sql \g

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u roo t -p test < C:\Users\smuf2\Downloads\person.sql' at line 1

I've been learning postgres and can do this easily with \i filename but can't figure out why I can't do it in mysql. I'm using mysql 8.0.26.

SQLrookie
  • 11
  • 5
  • All the command you list after your `mysql> SOURCE C:\Users\smuf2\Downloads\person.sql \g` attempts must not be expected in the MySQL shell (`mysql>` and the error message indicates that you try to run those in the MySQL shell) – t.niese Sep 13 '21 at 08:32
  • Changed the title. Thank you for the feedback. – SQLrookie Sep 13 '21 at 15:30

1 Answers1

1

You can import the file without first logging to MySQL.

Just open your shell/git-bash and do:

mysql -u username -p password database_name < dump.sql 
ikyuchukov
  • 565
  • 3
  • 12