Install, secure, and run MySQL locally on macOS using Homebrew.
Run brew update && brew install mysql
. Homebrew downloads the latest GA version, compiles it when needed, and links binaries under /opt/homebrew/bin
(Apple Silicon) or /usr/local/bin
(Intel).
The formula adds MySQL server, the client, utilities, a mysql@<version>
directory, and a launchd plist for background startup.
Use brew services start mysql
to launch MySQL at login via launchd. Stop it with brew services stop mysql
. For one-off sessions, run mysql.server start
and mysql.server stop
.
Execute mysql_secure_installation
. The wizard sets a root password, removes anonymous accounts, disables remote root logins, and drops the test database.
brew services start mysql
installs the launchd job automatically. Confirm with brew services list
; status should read started.
Connect with mysql -u root -p
. Then run:
CREATE DATABASE ecommerce;
USE ecommerce;
CREATE TABLE Products (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(80),
price DECIMAL(10,2),
stock INT
);
Insert a sample product: INSERT INTO Products(name,price,stock) VALUES ('Galaxy Tee',29.99,50);
. Query it with SELECT * FROM Products;
. If the row returns, your setup is complete.
Yes. The mysql
formula tracks the current GA release. Pin a version with brew install mysql@<version>
if you need stability.
By default under /opt/homebrew/var/mysql
(Apple Silicon) or /usr/local/var/mysql
(Intel). Adjust datadir
in my.cnf
if required.
Run brew services stop mysql
, then brew uninstall mysql
, and finally remove the data directory with rm -rf /opt/homebrew/var/mysql
.