PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How to include other .sql files in MySql command file?

 October 11, 2022     mysql, phpmyadmin     No comments   

Issue

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?


Solution

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).



Answered By - Bill Karwin
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing