Helpful reminders for working with your Bash, Terminal and command line.
Process status, see what processes are running on the machine
Confirm Apache is running
ps -ax | grep http
Confirm MySQL is running
ps -ax | grep mysql
list files and directories.
Create a new directory.
Copy files or directories.
Move (rename) files or directories.
mv myfile.txt destination-directory
Command Line Interface / Terminal Commands
Abort the current line or running script.
Clear the interface.
Put the cursor at the beginning of the current line.
Put the cursor at the end of the current line.
Switch to the last directory you were in.
Print the current working directory path.
Export a Database
You should not be logged-in to your MySQL server, simply run this command from the directory where you want the backup file put.
mysqldump -u [username] -p [database name] > [filename].sql
If you use MAMP, the mysqldump script is located in the MAMP application directory. You can make an alias to MAMPs version of mysqldump in your bash profile, or call it directly with something like:
/Applications/MAMP/Library/bin/mysqldump -u [username] -p [database name] > [filename].sql
Import a Database
You can import an .sql file from the command line, and from the MySQL shell.
You must have an empty database ready to import data to, so if you don’t, login to the MySQL shell and create the database with
CREATE DATABASE [database name];, then log-out of the MySQL shell.
To import, on the command line navigate to the directory where your .sql import file is located and enter the command:
mysql -u [username] -p [database_name] < [dumpfilename.sql]
You will be prompted for your password, then the import will proceed. When it is finished, your command prompt will return to normal.
This method will allow you to monitor the import progress. To import a .sql file into your local MySQL database, first login to the MySQL shell:
mysql -u [username] -p
Then run these commands in the MySQL shell to create a new database, switch to using it, then import a .sql file:
CREATE DATABASE [database name]; use [database name]; source [path to your sql file to import];