CLI Equivalents for Common MAMP PRO and Sequel Pro Tasks
Last Updated
A version of this article appeared on viget.com
![An elephant. Woodcut after C. Gessner](/posts/cli-equivalents-for-common-mamp-pro-and-sequel-pro-tasks/iI9dhleYHO-896.jpeg)
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:
Command Line MAMP PRO
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.
- Start the MAMP PRO servers:shellshell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServersshell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServers
- Stop the MAMP PRO servers:shellshell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServersshell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServers
- Create a host (replace host_name and root_path):shellshell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd createHost host_name root_pathshell/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd createHost host_name root_path
MAMP PRO-friendly Command Line Sequel Pro
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 isroot
by default, anddatabase_name
with your database’s name)command lineshell/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
command lineshell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p # and then entermysql> create database database_name; # don't forget the semicolonmysql> exitshell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p # and then entermysql> create database database_name; # don't forget the semicolonmysql> exitMAMP 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
shellshellls /Library/Application\ Support/appsolute/MAMP\ PRO/dbshellls /Library/Application\ Support/appsolute/MAMP\ PRO/dbThat will output something like
textmysql56_2018-11-05_16-25-13 mysql57textmysql56_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
shellshellls /Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql57shellls /Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql57The 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 isroot
by default, anddatabase_name
with your database’s name)shellshell/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 isroot
by default, anddatabase_name
with your database’s name)-
to export an uncompressed file
shellshell/Applications/MAMP/Library/bin/mysqldump -h localhost -u username -p database_name > the/output/path.sqlshell/Applications/MAMP/Library/bin/mysqldump -h localhost -u username -p database_name > the/output/path.sql -
to export an uncompressed file
shellshell/Applications/MAMP/Library/bin/mysqldump -h localhost -u username -p database_name | gzip -c > the/output/path.gzshell/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
shellshellssh ssh_user@ssh_host "mysqldump -u mysql_user -p database_name | gzip -c" | gunzip > the/output/path.sqlshellssh ssh_user@ssh_host "mysqldump -u mysql_user -p database_name | gzip -c" | gunzip > the/output/path.sql -
to export an uncompressed file
shellshellssh ssh_user@ssh_host "mysqldump -u mysql_user -p database_name | gzip -c" > the/output/path.gzshellssh 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) anddatabase_name
)shellshell/Applications/MAMP/Library/bin/mysql -h localhost -u username -p database_name < the/dump/path.sqlshell/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.
shellshellssh ssh_user@ssh_host "mysql -u username -p remote_database_name" < the/local/dump/path.sqlshellssh 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.
Articles You Might Enjoy
-
-
SSR Astro With Headless Craft CMS
Craft’s great data modelling and admin experience, with a server-rendered Astro front end.
-
Hometown: A Dynamic, Highly Configurable Git-Focused Zsh Theme
A fast zsh prompt that packs in a lot of Git status info