Tutorials Logic, IN info@tutorialslogic.com

MySQL Setup Install Connect

Installing MySQL on Windows

The easiest way to install MySQL on Windows is via the MySQL Installer, which bundles MySQL Server, MySQL Workbench, connectors, and other tools into a single setup wizard.

  • Download the MySQL Installer from dev.mysql.com/downloads/installer.
  • Run the installer and choose Developer Default (installs server + Workbench + connectors).
  • Follow the setup wizard - set a root password when prompted.
  • MySQL Server runs as a Windows service and starts automatically on boot.

Installing MySQL on macOS and Linux

Installing MySQL on macOS and Linux
-- macOS: Install via Homebrew
-- brew install mysql
-- brew services start mysql
-- mysql_secure_installation

-- Ubuntu / Debian
-- sudo apt update
-- sudo apt install mysql-server
-- sudo systemctl start mysql
-- sudo systemctl enable mysql
-- sudo mysql_secure_installation

-- CentOS / RHEL / Fedora
-- sudo yum install mysql-server        (CentOS 7)
-- sudo dnf install mysql-server        (CentOS 8 / Fedora)
-- sudo systemctl start mysqld
-- sudo systemctl enable mysqld
-- sudo grep 'temporary password' /var/log/mysqld.log

Starting and Stopping the MySQL Service

Once installed, you can manage the MySQL service from the command line:

Managing the MySQL Service

Managing the MySQL Service
-- Linux (systemd)
-- sudo systemctl start mysql
-- sudo systemctl stop mysql
-- sudo systemctl restart mysql
-- sudo systemctl status mysql

-- macOS (Homebrew)
-- brew services start mysql
-- brew services stop mysql
-- brew services restart mysql

-- Windows (Command Prompt as Administrator)
-- net start MySQL80
-- net stop MySQL80

Connecting via the MySQL CLI

The mysql command-line client lets you connect to any MySQL server and run SQL interactively. It's the fastest way to test queries and manage databases.

Connecting and First Commands

Connecting and First Commands
-- Connect as root (will prompt for password)
-- mysql -u root -p

-- Connect to a specific database
-- mysql -u root -p shop

-- Connect to a remote server
-- mysql -h 192.168.1.100 -P 3306 -u root -p

-- Once connected, run these essential commands:

-- List all databases
SHOW DATABASES;

-- Select a database to use
USE shop;

-- List all tables in the current database
SHOW TABLES;

-- Describe a table's structure
DESCRIBE customers;
-- or shorthand:
DESC orders;

-- Show the full CREATE table statement
SHOW CREATE table customers\G

-- Check current database and user
SELECT DATABASE(), USER();

MySQL Workbench

MySQL Workbench is the official GUI tool for MySQL. It provides a visual interface for database design, SQL development, server administration, and data migration. Key features include:

Download MySQL Workbench for free from dev.mysql.com/downloads/workbench. It's available for Windows, macOS, and Linux.

  • SQL Editor - Write and execute queries with syntax highlighting and auto-complete.
  • EER Diagram - Visually design your database schema with entity-relationship diagrams.
  • Server Administration - Monitor connections, manage users, and view server logs.
  • Data Export/Import - Backup and restore databases with a few clicks.
  • Migration Wizard - Migrate data from other databases (SQL Server, PostgreSQL, SQLite) to MySQL.

Creating a User and Granting Privileges

Creating a User and Granting Privileges
-- Create a new MySQL user
CREATE USER 'shopuser'@'localhost' IDENTIFIED BY 'SecurePass123!';

-- Grant all privileges on the shop database
GRANT ALL PRIVILEGES ON shop.* TO 'shopuser'@'localhost';

-- Grant only SELECT and INSERT on a specific table
GRANT SELECT, INSERT ON shop.orders TO 'shopuser'@'localhost';

-- Apply the privilege changes
FLUSH PRIVILEGES;

-- Show grants for a user
SHOW GRANTS FOR 'shopuser'@'localhost';

-- Revoke a privilege
REVOKE INSERT ON shop.orders FROM 'shopuser'@'localhost';

-- Drop a user
DROP USER 'shopuser'@'localhost';
Before you move on

MySQL Setup Install Connect Mastery Check

3 checks
  • The mysql command-line client lets you connect to any MySQL server and run SQL interactively.
  • It's the fastest way to test queries and manage databases.
  • MySQL Workbench is the official GUI tool for MySQL.

MySQL Setup Boundary

  • Administrative account in application code

    Avoid connecting the application as root. Create a scoped user for one database and grant only the statements the application requires.

MySQL Questions Learners Ask

Its bin directory may not be on PATH, or only the server service was installed.

Run SELECT @@hostname, @@port, DATABASE(), CURRENT_USER().

No. Create an account with only the permissions the application needs.

Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.