Import a mysql database into macOS via Terminal

Import a mysql/mariadb  database into macOS via the command line

I have found that phpmydmin on the Mac has issues with the max upload file size limit and changing the value in php.ini doesn’t always do the trick. With mysql already installed a quick trip to the terminal will sort this out.

Create the database if it isn’t already:

mysql -u [username] -p -e "create database [databasename];"

When prompted enter a password or enter one in the command – change -p to -p [password]).

Now navigate to the directory where the sql file has been uploaded to and import the mysql file:

mysql -u[username] -p [databasename] < [.sql filename]

That’s all there is to it !

You can also connect with mysql directly via the command line:

mysql -u [username] -p[password]

So after log in at the prompt, you are entered into a mysql session which you can exit by pressing control+’c’

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1935
Server version: 5.5.13 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

 

Leave all Comment