Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include MySQL database schema on GitHub?

Stackoverflow and MySQL-via-command-line n00b here, please be gentle! I've been looking around for answers to my question but could only find topics dealing with GitHubbing MySQL dumps (as in: data dumps) for collaboration or MySQL "version control" via GitHub, neither of which tells me what I want to know:

How does one include MySQL database schemas/information on tables with PHP projects on GitHub?

I want to share a PHP project on GitHub which relies on the existence of a MySQL database with certain tables. If someone wanted to copy/make use of this project, they would need to have these particular tables in place to make the script work (all tables but one are empty in the beginning and only get filled by the user over time, via the script; the non-empty table holds three values from the start). How does one go about this, what is common practice?

  • Would I just get a (complete) dump file of my own db/tables, then delete all the data parts (except for that one non-empty table), set all autoincrements to zero and then upload that .sql file to GitHub along with the rest of the project? OR
  • Is it best/better practice to write a (PHP) script with which the (maybe not-so-experienced) user can create these tables without having to use mysqldump/command line magic?

If solution #1 is the way to go, would I include further instructions on how to use such a .sql file?

Sorry if my questions sound silly, but as I said above, I myself am new to using the command line for MySQL-related things and had only ever used phpMyAdmin until yesterday (when I created my very first dump file with mysqldump - yay!).

like image 204
Kay Avatar asked Apr 29 '13 21:04

Kay


People also ask

How do I upload a schema in MySQL?

Importing a database from a fileFill in the fields with the connection information. Once connected to the database go to Data Import/Restore. Choose the option Import from Self-Contained File and select the file. Choose the destination database in Default Schema to be Imported To and then click on Start Import.

Can I use MySQL in GitHub?

GitHub uses MySQL as its main datastore for all things non- git , and its availability is critical to GitHub's operation. The site itself, GitHub's API, authentication and more, all require database access. We run multiple MySQL clusters serving our different services and tasks.


1 Answers

Common practice is to include an install script that creates the necessary tables, so solution #2 would be the way to go.

[edit] That script could ofc just replay a dump. ;)

You might also be interested in migrations: How to automate migration (schema and data) for PHP/MySQL application

like image 153
nietonfir Avatar answered Oct 06 '22 05:10

nietonfir