← Other topics

Forge Under the Hood - Databases (MySQL / MariaDB)

Video Notes

In this guide, I’ll explain how to manage MariaDB/MySQL databases directly via MySQL command line instead of via the Forge interface. You can use this information when troubleshooting or if you decide to cancel your Forge subscription and manage your own servers.

Credentials

Forge sets your server up with an admin database user named forge. If you didn’t record the password it generated for you when the server was created, you can reset it by visiting the Database section of your server’s settings in Forge and finding the section Manage Database Password.

MySQL command line

Now that you know your forge database user password, you can connect to the MySQL command line as this user with the following command:

> mysql -u forge -p

Enter your password when it prompts you to do so.

Once you’re connected, you can manage your databases and users as needed. Below is a summary of commands that cover all the database-related management tasks you can do via the Forge interface.

Managing databases

Show all the databases:

> SHOW DATABASES;

Delete a database (swap demo with the name of your database):

> DROP DATABASE demo;

Create a new database (swap demo with the name of your database):

> CREATE DATABASE demo;

Managing database users

See all database users:

> SELECT user FROM mysql.user;

Create a new database user:

> CREATE USER 'demoAdmin' IDENTIFIED BY 'your-password-here';

Grant a user privileges to a database:

> GRANT ALL PRIVILEGES ON demo . * TO 'demoAdmin';

The above command grants ALL PRIVILEGES to the given database. To set more restrictive privileges, check out the MariaDB docs on Database Privileges.

See what privileges a user has:

> SHOW GRANTS FOR 'demoAdmin';

See what users have privileges with a database:

> SELECT * FROM mysql.db WHERE Db = 'demo'\G

Delete a user:

> DROP USER 'demoAdmin';

Managing tables and data

All of the above commands focus on big-picture management of your databases and their users. Day-to-day management such as viewing/editing tables and data is beyond the scope of what Forge manages.

If you’re using Laravel, you should be using migrations to manage the creation and modifications of your tables.

For admin purposes of examining the structure and contents of your tables, you could use MySQL command line, phpMyAdmin, or a GUI program such MySQL WorkBench.

Resources

If this info helped you out, toss a coin in the tip jar?
← Other topics