Converting MySQL Schema to GitHub Wiki Markdown Tables
Issue
The user wants to convert their MySQL database schema into markdown format and present it as tables on GitHub Wiki. They are looking for a method to transform the CLI output of the schema into a Markdown representation.
Solution
Two stored procedures can be used to accomplish this task:
First Stored Procedure: describeTables_v2a
This stored procedure takes the following parameters:
- dbName: The database name to report on.
- theSession: An OUT parameter that receives the session number.
- deleteSessionRows: A boolean indicating whether to delete the output rows after completion.
- callTheSecondStoredProc: A boolean indicating whether to automatically call the second stored procedure for prettier printing.
The stored procedure:
- Queries the INFORMATION_SCHEMA database to retrieve the schema information.
- Stores the results in temporary tables for processing and formatting.
- Inserts the processed data into a permanent table called reportDataDefs.
- Returns the session number as an OUT parameter.
Second Stored Procedure: Print_Tables_Like_Describe
This stored procedure takes the session number as input and:
- Uses a cursor to iterate over the reportDataDefs table.
- Formats the data to resemble the output of DESCRIBE myTable.
- Inserts the formatted data into a temporary table called reportOutput.
- Returns the output as a result set.
Usage
To use these stored procedures, follow these steps:
- Create the Reporting101a database mentioned in the code.
- Execute the describeTables_v2a stored procedure with the appropriate parameters.
- If you want the prettier printing, execute the Print_Tables_Like_Describe stored procedure with the session number obtained from the first call.
The result will be a markdown table representing the MySQL schema, which can be copied and pasted into GitHub Wiki.
The above is the detailed content of How Can I Convert My MySQL Schema to GitHub Wiki Markdown Tables?. For more information, please follow other related articles on the PHP Chinese website!