Defining a test MySQL database
For test purposes, along with the source code for the book, we've provided an SQL file with sample data at https://github.com/dbierer/php7cookbook. The name of the database used in the recipes for this book is php7cookbook
.
How to do it...
- Define a MySQL database,
php7cookbook
. Also assign rights to the new database to a user calledcook
with the passwordbook
. The following table summarizes these settings:Item
Notes
Database name
php7cookbook
Database user
cook
Database user password
book
- Here is an example of SQL needed to create the database:
CREATE DATABASE IF NOT EXISTS dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE USER 'user'@'%' IDENTIFIED WITH mysql_native_password; SET PASSWORD FOR 'user'@'%' = PASSWORD('userPassword'); GRANT ALL PRIVILEGES ON dbname.* to 'user'@'%'; GRANT ALL PRIVILEGES ON dbname.* to 'user'@'localhost'; FLUSH PRIVILEGES;
- Import the sample values into the new database. The import file,
php7cookbook.sql
, is located at https://github.com/dbierer/php7cookbook/blob/master/php7cookbook.sql.