In the previous post, you were shown how to get started with Valet Plus. What wasn’t covered were steps involving configuring a MySQL database with Valet Plus.
By default, Valet+ comes installed with MySQL version 5.7 with compatibility for version 5.6. According to the documentation, Valet+ also includes a tweaked my.cnf which is aimed at improving speed
.
Similar to other packages that allow you to set up a local environment, such as MAMP, the default MySQL credentials are the following.
Username: root
Password: root
Ensure that you update your PHP application’s configuration files to contain these database credentials.
Valet+ contains a list of db
commands that can be used with MySQL.
Databases can be listed using the following command.
$ valet db ls
To create a database, use the valet db create
command, passing in the name
argument which is the name of the database.
$ valet db create foo_db
As well as creating databases with Valet, they can also be dropped. To drop a database, use the valet db drop
command, passing in the name
argument which is the name of the database.
$ valet db drop foo_db
Resetting databases, otherwise known and dropping and re-creating them, can be achieved using the valet db reset
command, passing in the name
argument which is the name of the database.
$ valet db reset foo_db
To export a database, use the valet db export
command, passing in two arguments. Firstly, the name of the file, eg. database.sql.gz. Secondly, the name of the database.
$ valet db export database_sql.gz foo_db
If no filename is given in the command then the following naming convention will be used: <database>-<date>.sql.gz
.
And lastly, to import a database, use the valet db import
command, passing in two arguments. Firstly, the name of the file, eg. database.sql.gz. Secondly, the name of the database.
$ valet db import database.sql.gz foo_db2
It should be noted that with all of the valet db
commands listed above, if no database name is given, Valet+ will attempt to find the closest git repository directory name. When it can’t find one it’ll use the current working directory name.