Creating an installation script
When we develop an application that interacts with a database, we need to create a script that recreates the same database structure on other computers. The creation of the application database is part of the installation process.
This database install script is usually a text file that contains the SQL commands to create the database. By convention, this file has a .sql
extension. As mentioned in Chapter 1, Installing MariaDB, the most common way to execute a file containing queries is by passing it to the mysql
command-line client. For example:
mysql -uroot -pmypassword < install_db.sql
The fastest way to create such a script is by using mysqldump
. This tool, mainly used to create backups, will be discussed in detail in Chapter 4, Importing and Exporting Data. It produces SQL files called
dumps. The basic syntax to create a dump from a single database is as follows:
mysqldump [options] db_name > <file_name>
If we only want to have the statements...