VS Vikesh Singh

Courses MySQL Lesson 2

MYSQL · LESSON 2 OF 18

Installing MySQL and Connecting for the First Time

· 3 min read

Now that you know what a relational database is, let's get MySQL running on your machine and connect to it for the first time.

Now that you know what a relational database is, let's get MySQL running on your machine and connect to it for the first time.

Installing MySQL On Your System

On macOS, the easiest route is Homebrew. Open your terminal and run brew install mysql, then brew services start mysql to keep it running in the background. On Windows, the simplest option is installing XAMPP or the official MySQL Installer from mysql.com, which bundles MySQL Server with a configuration wizard. On Linux, your package manager usually has it: sudo apt install mysql-server on Ubuntu/Debian.

Once installed, MySQL runs as a background service (sometimes called a daemon) listening on port 3306 by default. Think of it like a restaurant kitchen that's always open, waiting for orders (your SQL queries) to come in through that port.

Connecting With The Command Line

To actually "talk" to MySQL, you need a client. The simplest is the command line client that ships with MySQL itself:

mysql -u root -p

This tells MySQL: connect as the user root, and ask me for a password (-p). Type your password and press enter. If everything is set up correctly, you will land on a prompt that looks like mysql>. That prompt means you are now inside a live session talking directly to the database engine.

A common early mistake: people confuse "installing MySQL" with "installing a GUI tool." Tools like phpMyAdmin, TablePlus, DBeaver, or MySQL Workbench are just visual wrappers around the same connection you just made on the command line. They are convenient, especially for browsing data, but they are not the database itself. Learning the command line first means you will never be stuck if a GUI tool is unavailable, which happens more often than you'd expect on production servers.

Exploring Your First Session

Let's confirm the connection works and look around:

SHOW DATABASES;

This lists every database currently on your server. Fresh installs usually show a few system databases like information_schema, mysql, performance_schema, and sys. Don't touch those; they are MySQL's own internal bookkeeping, not space for your project.

To work inside a specific database, you "select" it:

USE information_schema;

This does not run a query against data; it just tells MySQL "for all my next commands, assume I mean this database unless I say otherwise." You will do this constantly, so get comfortable with it now.

Users Versus Application Data

One frequent point of confusion for beginners: a MySQL "user" (like root) is not the same as an operating system user on your computer, and it is definitely not the same as a row in a users table you might create later for your own app. MySQL has its own internal list of accounts and passwords, completely separate from anything your application logic creates. Mixing these up causes a lot of early confusion, so keep them mentally separate: MySQL accounts manage access to the server itself; your app's users table is just business data you store inside it.

A practical tip: never develop against the root account for a real project. Even locally, get in the habit of creating a dedicated account per project (you'll learn the exact command for this in later lessons once you understand privileges). For now, root is fine purely for learning.

Try It Yourself

Give it a try: install MySQL if you haven't, connect with mysql -u root -p, then run SHOW DATABASES; and SELECT VERSION();. The version command tells you exactly which MySQL release you're running, which matters because certain features in this course (like CTEs, covered later) need a minimum version.