Answer the question
In order to leave comments, you need to log in
How to automate the launch of sql scripts?
There is a folder that stores sql files for creating a database, tables in this database, importing data into these tables.
How to automate the launch of these sql scripts?
Through files with the extension sh? Or does the MySQL.connect driver have an execute method that has a function to read sql scripts? What is the easiest way to do this?
Answer the question
In order to leave comments, you need to log in
MySQL has its own built-in scheduler ( MySQL 8.0 Reference Manual / Stored Objects / ... ) that can do just about anything. You create an Event Procedure, set the frequency of execution - the server will do the rest. Generally without help/management from outside.
People usually like to suggest external schedulers (usually CRON) - I strongly do not recommend if the code that needs to be executed is pure SQL. Another thing is when you need to execute scripts in other languages or external applications - yes, you probably can’t do without cron. Although there is a way here too - connect an external module with the required functionality.
There is a folder that stores sql files for creating a database, tables in this database, importing data into these tables.
How to automate the launch of these sql scripts?
The easiest way will really be through a shell script ("a file with the sh extension"), and even writing this command to a file is not necessary, but you can simply execute it in the console:
for file in `ls /path/to/files/*.sql`; do mysql -uUSER -pPASSWORD DATABASE < $file ; done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question