-1

I have a text file that contains about 302 commands to be executed by mySql server, all of them are in a .txt file, arranged in the same way:

USE Plate;
INSERT INTO B (S, P) values ("BI","Bia")

USE Plate;
INSERT INTO B (S, P) values ("BS","Suw")

USE Plate;
INSERT INTO B (S, P) values ("BL","Lom")

how could I (cause copying and pasting them into mySQL workbench doesn't seem like the wisest idea) do all of them at once?

additional info (just to be sure I guess):

USE Plate;
INSERT INTO B (S, P) values ("BL","Lom")

those should be executed together.

JustSightseeing
  • 1,460
  • 3
  • 17
  • 37
  • “*copying and pasting them into mySQL workbench doesn't seem like the wisest idea*” Er, why not, exactly…? What are you basing this claim on? – esqew Dec 25 '21 at 18:49
  • Also, what’s the purpose of the redundant `USE` statements here? – esqew Dec 25 '21 at 18:49
  • 1
    Finally, can you provide some justification as to how this *isn’t* a duplicate of https://stackoverflow.com/questions/8940230/how-to-run-sql-script-in-mysql? – esqew Dec 25 '21 at 18:51
  • 1. “copying and pasting them into mySQL workbench doesn't seem like the wisest idea” cause there are about 300 lines to select and copy, one by one 2. I wish I knew, I was not the one who wrote this text file – JustSightseeing Dec 25 '21 at 18:57
  • 3. I might've overlooked this answer cause the file had other extension – JustSightseeing Dec 25 '21 at 18:58
  • 2
    Side note: Don't get used to use double quotes for string or date literals. Yes, sadly MySQL accepts that, but in SQL double quotes are usually for identifiers, such as column names. Should you ever use another DBMS (or future MySQL versions become more sane about this) you'll likely get an "invalid object name" error. Always use single quotes for string or date literals. – sticky bit Dec 25 '21 at 19:14
  • 2
    MySQL Workbench has a "File/ Open SQL Script" menu. You only need change the default extension list to be able to see all files. – Álvaro González Dec 25 '21 at 19:28
  • Does this answer your question? [How to run SQL script in MySQL?](https://stackoverflow.com/questions/8940230/how-to-run-sql-script-in-mysql) – esqew Dec 25 '21 at 19:46

1 Answers1

2

You seem to be working under limitations of your own invention.

There's no reason to paste just one line at a time into MySQL Workbench. Leaving aside other methods of loading the file, just copy and paste the entire file, redundant USE statements and all, into a Workbench query window and hit the Execute button.

MySQL Workbench will happily execute the entire script, line by line.

  • not really my invention but you are correct about the limitations, that's all I needed, thanks :) – JustSightseeing Dec 26 '21 at 00:27
  • I think `load data` statement can be use, [load-data](https://dev.mysql.com/doc/refman/5.7/en/load-data.html) – HaiZi Dec 26 '21 at 04:09
  • @HaiZi, Load data can't execute SQL scripts. At best, it will load the text of the SQL script as strings, not executing the SQL. – Bill Karwin Dec 26 '21 at 06:13