MySQL
Mac OS Lion
command line
server startup
tutorial

How to start MySQL server from command line on Mac OS Lion?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Starting MySQL from the command line on Mac OS Lion usually depends on how MySQL was installed. Older package installs use the mysql.server script under /usr/local/mysql, while other setups may use launch agents or Homebrew style service management on newer systems. The safest workflow is to detect installation type, start with the right command, then verify server state.

Identify Your MySQL Installation Layout

Before running start commands, locate the server binaries and support scripts. This avoids calling a wrong path and assuming startup failed.

bash
which mysql
ls -ld /usr/local/mysql
ls /usr/local/mysql/support-files 2>/dev/null

If support-files/mysql.server exists, you can use the package style startup script. If not, check whether MySQL is managed by another service mechanism.

Also verify whether a server is already running:

bash
ps aux | grep mysqld | grep -v grep
lsof -iTCP:3306 -sTCP:LISTEN

If port 3306 is already listening, startup may not be needed.

Start and Stop with mysql.server

For classic installer based deployments, use the bundled management script.

bash
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server status

Stop and restart commands:

bash
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server restart

If command works, you should see a running mysqld process and socket file under the MySQL data directory.

Validate Connection from CLI

After startup, verify both server reachability and authentication.

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

If this succeeds, your server is active and accepting queries. If login fails, check root credentials and authentication plugin settings for your MySQL version.

For quick health check without entering interactive shell:

bash
mysqladmin -u root -p ping

Expected output includes mysqld is alive.

Troubleshoot Common Startup Failures

When startup fails, inspect logs first. Typical log locations include /usr/local/mysql/data or paths configured in my.cnf.

bash
ls /usr/local/mysql/data/*.err
cat /usr/local/mysql/data/*.err | tail -n 100

Common failure reasons:

  • Existing process already bound to port 3306.
  • Corrupted pid file after abrupt shutdown.
  • Permission issues on MySQL data directory.
  • Invalid configuration directives in my.cnf.

If stale pid file blocks startup, remove it only after confirming no active mysqld process is running.

bash
sudo rm -f /usr/local/mysql/data/*.pid
sudo /usr/local/mysql/support-files/mysql.server start

Optional Convenience Alias

If you run these commands frequently, add aliases to your shell profile.

bash
1cat >> ~/.bash_profile <<'EOF_ALIAS'
2alias mysqlstart='sudo /usr/local/mysql/support-files/mysql.server start'
3alias mysqlstop='sudo /usr/local/mysql/support-files/mysql.server stop'
4alias mysqlstatus='sudo /usr/local/mysql/support-files/mysql.server status'
5EOF_ALIAS
6
7source ~/.bash_profile

On systems using zsh, place them in ~/.zshrc instead.

Note About Mac OS Lion Age

Mac OS Lion is an old platform with outdated libraries and security posture. If this environment is for legacy compatibility only, keep it isolated and avoid public exposure. For active development, migrate to a supported macOS version or use a containerized database workflow.

Optional Startup Automation

If you need MySQL available after login without manual start commands, you can configure launchd for legacy environments. Use this carefully, and ensure it points to the same MySQL installation path used in manual commands.

bash
1sudo cp /usr/local/mysql/support-files/mysql.server /usr/local/bin/mysql.server
2sudo chmod +x /usr/local/bin/mysql.server
3
4# Example periodic health check script call
5/usr/local/bin/mysql.server status

Even with automation, keep manual start and stop commands documented for troubleshooting sessions.

Common Pitfalls

  • Running Homebrew service commands on a package installation layout.
  • Assuming startup succeeded without checking process list or server ping.
  • Editing or deleting pid files while another mysqld instance is active.
  • Ignoring error log output and retrying blindly.
  • Keeping legacy OS hosts exposed to public networks.

Summary

  • Determine MySQL installation type before choosing startup commands.
  • Use mysql.server under /usr/local/mysql/support-files for classic package installs.
  • Validate startup with mysqladmin ping and a test query.
  • Read error logs first when startup fails.
  • Treat Mac OS Lion as legacy and isolate it from modern production workloads.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.