MySQL Configuration and Client Tools
Introduction
After install, you need reliable start/stop habits, optional security hardening, and a client to run SQL. This chapter covers service management across platforms, mysql_secure_installation recap, useful GUI tools, and your first learn_db session—not JDBC wiring yet.
Prerequisites
Start and Stop MySQL
| Platform | Start | Stop |
|---|---|---|
| Windows | Services → MySQL80 → Start | Stop service |
| macOS (Homebrew) | brew services start mysql | brew services stop mysql |
| Linux (systemd) | sudo systemctl start mysql | sudo systemctl stop mysql |
| Docker | docker start mysql-learn | docker stop mysql-learn |
Verify listening port:
# Linux/macOS
ss -tlnp | grep 3306
# or
lsof -i :3306mysql_secure_installation Recap
Run once after fresh install:
mysql_secure_installationGoals:
- Strong root password
- No anonymous users
- Remove test database
- Reload privileges
For Docker, set passwords via MYSQL_* env vars at container create instead.
Client Tools
| Tool | Type | Best for |
|---|---|---|
mysql CLI | Terminal | Scripts, tutorials, servers |
| MySQL Workbench | Official GUI | ER diagrams, visual admin |
| DBeaver | Free GUI | Multi-database teams |
| DataGrip | JetBrains IDE | Java developers |
| HeidiSQL | Windows GUI | Lightweight Windows admin |
Hello Code examples use mysql CLI—skills transfer to any GUI.
mysql Client Basics
Connect:
mysql -u root -pSelect default database:
mysql -u root -p learn_dbRun one statement from shell:
mysql -u root -p -e "SELECT VERSION();"Execute SQL file:
mysql -u root -p learn_db < script.sqlConfiguration Files (Awareness)
| OS | Common path |
|---|---|
| Linux | /etc/mysql/my.cnf, /etc/mysql/mysql.conf.d/mysqld.cnf |
| macOS Homebrew | /opt/homebrew/etc/my.cnf |
| Windows | C:\ProgramData\MySQL\MySQL Server 8.0\my.ini |
Important settings (do not change blindly):
[mysqld]
port=3306
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ciRestart service after edits.
First Session Checklist
-- Show server version and current user
SELECT VERSION(), CURRENT_USER();
-- List existing databases (system DBs included)
SHOW DATABASES;Create practice database (preview of next chapter):
CREATE DATABASE IF NOT EXISTS learn_db
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
USE learn_db;
SELECT DATABASE();Code explanation:
utf8mb4supports full Unicode including emoji—always prefer over legacyutf8USEsets default database for following statements
Tip
Set Default in ~/.my.cnf
[client]
user=learn_user
password=your_password
database=learn_dbKeep file mode 600 on Unix—contains secrets.
Environment Variable PATH
Ensure mysql is on PATH (Windows install chapter). Linux/macOS packages usually configure automatically.
FAQ
mysql vs mysqld?
mysqld is server daemon; mysql is client—learners use mysql.
Workbench connection refused?
Server not running or wrong port/host—check service status.
Where is error log?
Linux: /var/log/mysql/error.log; Windows: under ProgramData\MySQL\...; Docker: docker logs.
Change root password?
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpass';
Multiple MySQL versions?
Docker different ports; native one version per machine is simpler.
MySQL Shell?
Advanced CLI (mysqlsh)—optional; classic mysql enough here.