MySQL Installation
Installing MySQL is the first step before you can run queries or connect it to your Next.js project. In this guide, we will cover installation for Windows, macOS, and Linux (Ubuntu), along with configuration, creating users, and integrating it with Next.js.
1. Install on Windows
- Download MySQL installer from MySQL Official Website.
- Select Developer Default during setup.
- Set root password and optionally create a new user.
- Install MySQL Workbench (GUI).
2. Install on macOS
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install mysql brew services start mysql mysql_secure_installation3. Install on Linux (Ubuntu)
sudo apt update sudo apt install mysql-server sudo mysql_secure_installation sudo systemctl start mysql4. Verify Installation
mysql --version5. Create Database & User
CREATE DATABASE nextjs_app; CREATE USER 'nextjs_user'@'localhost' IDENTIFIED BY 'mypassword'; GRANT ALL PRIVILEGES ON nextjs_app.* TO 'nextjs_user'@'localhost'; FLUSH PRIVILEGES;6. Connect MySQL with Next.js
npm install mysql2Now you can use connectDB() inside your Next.js /pages/apiroutes to query MySQL.