Mysql In Mac Terminal



What’s the matter?

For years MySQL and MariaDB have been the most popular OpenSource Database Managment Systems world wide. So it is no surprise that most of the common software support them natively.

There are actually only two large areas of databases. Relational databases (MySQL, PostgreSQL, Oracle and similar), and so-called non-relational databases, also called no-SQL databases.

MySQL and MariaDB belong to the relational databases.

MySQL Workbench is a very popular MySQL database manager for developers. It provides handy administration tools like server configuration, user management, and many others. It is available for MAC OS, Linux, and Windows operating systems. We advise all those budding developers who want to learn database administration to use it to their advantage. To do this, connect to your server via SSH. On Windows, you can use the program PuTTY, on Linux, use any terminal program (like xTerm), and on MAC OS X you simply use the built-in terminal (type “terminal” in the Spotlight search and confirm with Enter). If you are logged on to the server, you can simply log on to your MySQL or MariaDB server. Choose a remote MySQL connection method. You can use either of the following methods to access your MySQL databases remotely: SSH tunnel: This is the more secure method. You set up an SSH tunnel that forwards a port on your local computer to the remote MySQL server. WARNING: You should properly shutdown the MySQL server.Otherwise, you might corrupt the database and might have problems restarting it. BUT, if you encounter problem shutting down the server normally, you may kill the 'mysqld' process in Task Manager (for Windows); or Activity Monitor (for macOS); or System Monitor (for Ubuntu).

We work with these databases very often and have found that most tasks can be done with a handful of commands. In this article, we will guide you through the commands of MySQL or MariaDB to create a new database.

Then we will show you how to delete the new (or any other) database.

Starting MySQL Console

First, log on to your MySQL or MariaDB server. To do this, connect to your server via SSH. On Windows, you can use the program PuTTY, on Linux, use any terminal program (like xTerm), and on MAC OS X you simply use the built-in terminal (type “terminal” in the Spotlight search and confirm with Enter).

If you are logged on to the server, you can simply log on to your MySQL or MariaDB server. If you have not yet created a new user who has the rights to create new databases, use the user ‘root’.

Log on as root user on MySQL

The registration process is very simple. Once you are logged in to your server, you simply use mysql-binary to login.

If your MySQL or MariaDB server has set a password, then you call the program as follows:

If you have not set a password for the user root, do not use the parameter ‘-p’. If everything goes well, then you should see the following output:

Directly after logging in as an administrative user (root), you can create new databases or display existing databases.

List all Databases

If you have a freshly installed system with a new MySQL or MariaDB instance, then probably not all too many databases exist. First of all, let MySQL or MariaDB show you all existing databases with the command ‘SHOW DATABASES;’. Make sure you have the command in your SQL console with the semicolon; at the end.

As you see, my server is boring and empty.

Start mysql in mac terminal

Create a MySQL or MariaDB database

DaCreating a new database under MySQL or MariaDB is just as easy as listing the existing databases. Just use the SQL command ‘CREATE DATABASE <name>;’ to create a Database with the name <name>.

If everything went well, you just created a database called blog. If you now list all your databases again, you can find the newly created database in the output:

Deleting a MySQL or MariaDB database

If you delete a database directly with the command line tool, be sure to delete the correct one. Once the database is deleted, there is normally no going back.

Mysql mac terminal create database

First list all databases on your server. Use the command ‘SHOW DATABASES;’ in the mysql-console like in the example above.

Now copy the name of the database you want to delete.

To do delete a database you need the command ‘DROP DATABASE’. The syntax is similar to creating a database. ‘DROP DATABASE <name>;’, where <name> is the name of the database you want to delete.

An example could look like this:

The mysql-console is not very helpful here. If everything went correctly it will show you a simple “OK”.

Use the command ‘SHOW DATABASES;’ to double check the database was deleted.

More information

Terminal
  • How to create a User and grant privileges on MySQL and MariaDB. (German only)

What’s the matter? For years MySQL and MariaDB have been the most popular OpenSource Database Managment Systems world wide. So it is no surprise that most of the common software support them natively. There are actually only two large areas of databases. Relational databases (MySQL, PostgreSQL, Oracle and similar), and so-called non-relational databases, also called […]

Thank you for your feedback!
We will get back to you as soon as the article is finished.

I’m Dan Benjamin. I’m a podcaster, writer, and software developer based in Austin, Texas. I’m the founder of Fireside.fm, a podcast hosting and analytics platform I helped create to make podcast hosting easy, reliable, and fun. I’m also the founder of the 5by5 Studios where I get to talk to with my friends and heroes while fullfilling my lifelong dream of doing talk radio.

In a past life, I was a corporate stooge and eventual CTO of several startups. I've written for A List Apart and O’Reilly, made screencasts for PluralSight, and been coding for almost two decades. I co-founded a pre-Facebook social network about wine called Cork’d (acquired by Gary Vaynerchuk) and a website for parents called Playgrounder (aquired by Uncrate).

Projects

Mac

I enjoy making things that help people. Here's a list of my recent projects.

How To Access Mysql In Mac Terminal

Voice Work

Hire me for voice work, narration, commercials, voice over for your videos, and more.

Mysql Mac Terminal Setup

I'm available through Voices.com and for smaller projects, I'm available on Fiverr.

Dan Benjamin Live!

I do a daily morning stream with a focus on news and analysis. I also make videos teaching people how to podcast, including tutorials, gear reviews and recommendations, tips, tricks, advice, and more. I love doing this, so please like and subscribe …

Install mysql in mac terminal

Fireside

Fireside is a podcast hosting and analytics platform I created to make podcast hosting easy, reliable, and fun. I took everything I've learned as a podcaster since 2006 (and full-time at 5by5 since 2009) and built it into Fireside. It took years to build, and if you're interested in podcasting, I'd love for you to try it.

5by5

Started in 2009, 5by5 was one of the first podcast networks around. We make shows for geeks, gamers, and people like you. I host a number of shows there, and we producer about 25 total shows per week. 5by5 exists due to the generosity of our sponsors and the listeners who support us.

Podcast Method (Website and Podcast)

I love podcasting, and I love to teach people what I know about it. Podcast method is both a website and a podcast. The website lists my recommended gear and equipment, with advice about how to use it. The podcast talks in detail about these topics, and I do my best to answer listener questions each week.

Bacon Method

I love bacon but I hate mess. Fortunately, I discovered a way to make perfect, crispy bacon every time with the minimum amount of preparation and cleanup. This site teaches you how.