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

PlatformStartStop
WindowsServices → MySQL80 → StartStop service
macOS (Homebrew)brew services start mysqlbrew services stop mysql
Linux (systemd)sudo systemctl start mysqlsudo systemctl stop mysql
Dockerdocker start mysql-learndocker stop mysql-learn

Verify listening port:

bash
# Linux/macOS
ss -tlnp | grep 3306
# or
lsof -i :3306

mysql_secure_installation Recap

Run once after fresh install:

bash
mysql_secure_installation

Goals:

  • 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

ToolTypeBest for
mysql CLITerminalScripts, tutorials, servers
MySQL WorkbenchOfficial GUIER diagrams, visual admin
DBeaverFree GUIMulti-database teams
DataGripJetBrains IDEJava developers
HeidiSQLWindows GUILightweight Windows admin

Hello Code examples use mysql CLI—skills transfer to any GUI.

mysql Client Basics

Connect:

bash
mysql -u root -p

Select default database:

bash
mysql -u root -p learn_db

Run one statement from shell:

bash
mysql -u root -p -e "SELECT VERSION();"

Execute SQL file:

bash
mysql -u root -p learn_db < script.sql

Configuration Files (Awareness)

OSCommon path
Linux/etc/mysql/my.cnf, /etc/mysql/mysql.conf.d/mysqld.cnf
macOS Homebrew/opt/homebrew/etc/my.cnf
WindowsC:\ProgramData\MySQL\MySQL Server 8.0\my.ini

Important settings (do not change blindly):

ini
[mysqld]
port=3306
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci

Restart service after edits.

First Session Checklist

sql
-- 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):

sql
CREATE DATABASE IF NOT EXISTS learn_db
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;
 
USE learn_db;
 
SELECT DATABASE();

Code explanation:

  • utf8mb4 supports full Unicode including emoji—always prefer over legacy utf8
  • USE sets default database for following statements

Tip

Set Default in ~/.my.cnf

ini
[client]
user=learn_user
password=your_password
database=learn_db

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