I have multiple tables to create in my current project (each CREATE in its own .sql file) and the order of creation is important, so I'd like one file to create them all in the proper order when I create a new database. This is not a show-stopper, just an inconvenience. In MySQL (using phpMyAdmin) I'd like a single .sql file that will execute multiple other .sql files. I'm looking for something equivalent to Oracle's ability with the "@" sign (or keyword "start"):
@create_users.sql @create_services.sql
Does MySql/phpMyAdmin have a similar command as Oracle to do this?
CodePudding user response:
The mysql client has a command source
that you can put into a .sql file. It reads another .sql file that you name.
This is analogous to the command of the same name in some POSIX shell scripting languages.
You might like to read this manual page to understand other built-in commands of the MySQL client: https://dev.mysql.com/doc/refman/en/mysql-commands.html
Re your comment: You asked in your question above if MySQL/phpMyAdmin has a similar command. MySQL does.
phpMyAdmin is not a product of MySQL, it's an independent community tool, and it does not have a similar command. phpMyAdmin has an import tab, with which you can upload one .sql file at a time.
The .sql files read by phpMyAdmin don't support all the same built-in commands that the command-line mysql client supports. For example, it does not support the source
command, because that would require the web application phpMyAdmin to somehow read additional files from your computer. Web applications can't do that (and it's a good thing they can't).