MySQL database operation via terminal for MAMP [mac] users
We will be demonstrating on how to use MySQL from terminal of MAC OS which has MAMP installed on it.
Some common functionalities will include :
- Selecting a database and running related commands
- Importing database
- Exporting database
First step would be to run MAMP and make sure MYSQL server is ON
Open terminal and run the following command :
Let’s now enter MySQL mode with our default root user by the following command. The following command also solves the common error few user face i.e
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘list databases’ at line 1 .The command instead of list databases can be use database or any other mysql command. The reason for the same is that the person didn’t logged in using root user / mysql user
./mysql -uroot -p
It will ask for password, you would need to just press enter as by default password is blank in MAMP mysql user. In case you have explicitly set a password for root user, then enter that.
You will get a screen something like this :
Now, we can use commands like List DATABASES ; to view your database , USE DB_name; etc.
For importing a mysql dump into database, we can use following commands :
USE basezap_db;source /User/basezap/Downloads/mysqlbackup.sql;
This will import your mysql dump. You would need to modify the path to matching your file location.