MySQL - installing and setting up MySQL on Windows, macOS, and Linux
1. Choose Your Installation Method
MySQL can be installed in several ways:
-
MySQL Installer (Windows)
-
DMG Package (macOS)
-
APT/YUM (Linux)
-
Docker (cross-platform)
2. Installation
A. Windows
-
Download MySQL Installer from the official site:
https://dev.mysql.com/downloads/installer/ -
Run the installer and choose “Developer Default” (includes server, Workbench, Shell, connectors, etc.).
-
During setup:
-
Choose Standalone MySQL Server.
-
Set a root password (remember this!).
-
Optionally, create additional user accounts.
-
-
Complete the installation.
B. macOS
-
Download the MySQL DMG archive:
https://dev.mysql.com/downloads/mysql/ -
Open the DMG and run the installer.
-
After installation:
-
Start MySQL using System Preferences → MySQL.
-
Set root password during installation or via command line.
-
-
Add MySQL to PATH (optional, for terminal use):
echo 'export PATH="/usr/local/mysql/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
C. Linux
Ubuntu/Debian
sudo apt update
sudo apt install mysql-server
sudo systemctl start mysql
sudo systemctl enable mysql
CentOS/RHEL
sudo yum install mysql-server
sudo systemctl start mysqld
sudo systemctl enable mysqld
Secure installation:
sudo mysql_secure_installation
-
Set root password
-
Remove anonymous users
-
Disallow remote root login
-
Remove test database
D. Docker (Cross-platform)
docker pull mysql:latest
docker run --name mysql-server -e MYSQL_ROOT_PASSWORD=yourpassword -p 3306:3306 -d mysql:latest
-
Access MySQL:
docker exec -it mysql-server mysql -uroot -p
3. Verify Installation
mysql -u root -p
-
Enter the root password.
-
If you see the MySQL prompt (
mysql>
), the installation was successful.
4. Basic Setup
-
Create a database
CREATE DATABASE my_database;
-
Create a user and grant privileges
CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';
FLUSH PRIVILEGES;
-
Connect to the database
mysql -u my_user -p my_database
5. Optional Tools
-
MySQL Workbench: GUI for database design and queries.
-
MySQL Shell: Advanced command-line client.
-
phpMyAdmin: Web-based management tool.