A collection of components for displaying Git information in your prompt
A version of this article appeared on viget.com
Working on website front ends I sometimes use MAMP PRO to manage local hosts and Sequel Pro to manage databases. Living primarily in my text editor, a terminal, and a browser window, moving to these click-heavy dedicated apps can feel clunky. Happily, the tasks I have most frequently turned to those apps for —starting and stopping servers, creating new hosts, and importing, exporting, deleting, and creating databases— can be done from the command line.
I still pull up MAMP PRO if I need to change a host’s PHP version or work with its other more specialized settings, or Sequel Pro to quickly inspect a database, but for the most part I can stay on the keyboard and in my terminal. Here’s how:
You can start and stop MAMP PRO’s servers from the command line. You can even do this when the MAMP PRO desktop app isn’t open.
Note: MAMP PRO’s menu icon will not change color to reflect the running/stopped status when the status is changed via the command line.
shell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServers
shell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServers
shell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServers
shell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServers
shell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd createHost host_name root_path
shell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd createHost host_name root_path
Note: if you don’t use MAMP PRO, just replace the /Applications/MAMP/Library/bin/mysql with mysql.
In all of the following commands, replace username with your user name (locally this is likely root) and database_name with your database name. The -p (password) flag with no argument will trigger an interactive password prompt. This is more secure than including your password in the command itself (like -pYourPasswordHere). Of course, if you’re using the default password root is not particular secure to begin with so you might just do -pYourPasswordHere.
Setting the -h (host) flag to localhost or 127.0.0.1 tells mysql to look at what’s on localhost. With the MAMP PRO servers running, that will be the MAMP PRO databases.
shell% /Applications/MAMP/Library/bin/mysql mysql_options # opens an interactive mysql sessionmysql> some command; # don't forget the semicolonmysql> exit;
shell% /Applications/MAMP/Library/bin/mysql mysql_options # opens an interactive mysql sessionmysql> some command; # don't forget the semicolonmysql> exit;
Create a local database: with the MAMP PRO servers running, run this (replace username with your username, which is root by default, and database_name with your database’s name)
shell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p -e "create database database_name"
shell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p -e "create database database_name"
or
shell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p # and then entermysql> create database database_name; # don't forget the semicolonmysql> exit
shell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p # and then entermysql> create database database_name; # don't forget the semicolonmysql> exit
MAMP PRO’s databases are stored in /Library/Application Support/appsolute/MAMP PRO/db so to confirm that it worked you can run the following command to output the available MySQL versions
shellls /Library/Application\ Support/appsolute/MAMP\ PRO/db
shellls /Library/Application\ Support/appsolute/MAMP\ PRO/db
That will output something like
textmysql56_2018-11-05_16-25-13 mysql57
textmysql56_2018-11-05_16-25-13 mysql57
(Alternatively open the main MAMP PRO window and click on the MySQL “servers and services” item. In my case it shows “Version: 5.7.26”.)
Now look in the relevant MySQL directory
shellls /Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql57
shellls /Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql57
The newly created database should be in the list
Delete a local database: with the MAMP PRO servers running, run this (replace username with your username, which is root by default, and database_name with your database’s name)
shell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p -e "drop database database_name"
shell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p -e "drop database database_name"
Export a dump of a local database. Note that these uses mysqldump not mysql (replace username with your username, which is root by default, and database_name with your database’s name)
to export an uncompressed file
shell/Applications/MAMP/Library/bin/mysqldump -h localhost -u username -p database_name > the/output/path.sql
shell/Applications/MAMP/Library/bin/mysqldump -h localhost -u username -p database_name > the/output/path.sql
to export an uncompressed file
shell/Applications/MAMP/Library/bin/mysqldump -h localhost -u username -p database_name | gzip -c > the/output/path.gz
shell/Applications/MAMP/Library/bin/mysqldump -h localhost -u username -p database_name | gzip -c > the/output/path.gz
Export a local dump from an external database over SSH. Note that this uses mysqldump not mysql (replace ssh-user, ssh_host, mysql_user, database_name, and the output path)
to export an uncompressed file
shellssh ssh_user@ssh_host "mysqldump -u mysql_user -p database_name | gzip -c" | gunzip > the/output/path.sql
shellssh ssh_user@ssh_host "mysqldump -u mysql_user -p database_name | gzip -c" | gunzip > the/output/path.sql
to export an uncompressed file
shellssh ssh_user@ssh_host "mysqldump -u mysql_user -p database_name | gzip -c" > the/output/path.gz
shellssh ssh_user@ssh_host "mysqldump -u mysql_user -p database_name | gzip -c" > the/output/path.gz
Import a local database dump into a local database. With the MAMP PRO servers running, run this (replace username (root by default) and database_name)
shell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p database_name < the/dump/path.sql
shell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p database_name < the/dump/path.sql
Import a local database dump into a remote database over SSH. Use care with this one. But if you are doing it with Sequel Pro —maybe you are copying a Craft CMS site’s database from a production server to a QA server— you might as well be able to do it on the command line.
shellssh ssh_user@ssh_host "mysql -u username -p remote_database_name" < the/local/dump/path.sql
shellssh ssh_user@ssh_host "mysql -u username -p remote_database_name" < the/local/dump/path.sql
For me, using the command line instead of the MAMP PRO and Sequel Pro GUI means less switching between keyboard and mouse, less opening up GUI features that aren’t typically visible on my screen, and generally better DX. Give it a try! And while MAMP Pro’s CLI is limited to the essentials, command line mysql of course knows no limits. If there’s something else you use Sequel Pro for, you may be able to come up with a mysql CLI equivalent you like even better.
Git Prompt Kit: Configurable, Fast Git Status Components For Custom Zsh Themes
A collection of components for displaying Git information in your prompt
Fundamental Twig for Front-End Development
Your comprehensive guide for Twig front-end view templates.
Hometown: A Dynamic, Highly Configurable Git-Focused Zsh Theme
A fast zsh prompt that packs in a lot of Git status info