Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
FAQs Support
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials

MySQL Getting Started

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.

  1. Download the MySQL Installer from dev.mysql.com/downloads/installer.
  2. Run the installer and choose Developer Default (installs server + Workbench + connectors).
  3. Follow the setup wizard — set a root password when prompted.
  4. MySQL Server runs as a Windows service and starts automatically on boot.
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
-- 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
-- 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:

  • 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.

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

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';

Ready to Level Up Your Skills?

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