This project is a modern web application built using Next.js with MySQL database integration. It demonstrates how to connect a Next.js application to a MySQL database, fetch data dynamically, and display it on the frontend. The application is styled using Bootstrap for responsiveness and an enhanced user interface.
- MySQL database integration.
- API routes for secure data fetching.
- Dynamic rendering of database tables on the frontend.
- Integration of Bootstrap for styling and responsive design.
- Clear folder structure for scalability and extensibility.
- Next.js: React-based framework for building modern web apps.
- MySQL: Relational database management system for data storage.
- Bootstrap: Framework for responsive design and UI components.
- JavaScript: Programming language for both backend and frontend logic.
Ensure the following tools are installed on your machine:
git clone https://github.com/anupammo/mysql-nextjs.git
cd mysql-nextjs
Run the following command to install project dependencies:
npm install
- Import the database schema from the
database/nextjs_db.sql
file:mysql -u root -p < database/nextjs_db.sql
- Verify the database is set up by running:
mysql -u root -p SHOW DATABASES;
Create a .env
file in the root directory and add the following:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=nextjs_db
DB_PORT=3307
Replace yourpassword
with your MySQL root password (leave blank if no password).
Start the development server with:
npm run dev
Visit http://localhost:3000 in your browser to view the application.
my-nextjs-project/
├── src/
│ ├── app/
│ │ ├── globals.css # Global styles
│ │ ├── layout.tsx # Application layout
│ │ └── page.tsx # Main page
│ └── api/
│ └── employees
│ └── route.js # API route for fetching employee data
├── database/
│ └── nextjs_db.sql # Database schema and sample data
└── db.js # MySQL database connection
├── .env # Environment variables
├── package.json # Project dependencies
└── README.md # Project documentation
- The application dynamically renders data from the
employees
table in MySQL. - You can add, modify, or delete rows directly in the database, and the changes will reflect in the app.
Contributions are welcome! Follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature-name
- Commit your changes:
git commit -m "Add your message here"
- Push the branch:
git push origin feature/your-feature-name
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or support, feel free to reach out to Anupam Mondal.