Giter Club home page Giter Club logo

vercel-nextjs-app-azure-db-mysql's Introduction

Next.js + Azure Database for MySQL

This is a Next.js project that uses Prisma to connect to a Azure database for MySQL database and Tailwind CSS for styling.

Prerequisites

Set up the database

In the Azure portal, go to MySQL Flexible server resource and select Add to create new database called products.

image

Set up the starter Next.js app

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

npx create-next-app nextjs-azure-mysql
# or
yarn create next-app nextjs-azure-mysql
# or
pnpm create next-app nextjs-azure-mysql

Download SSL certificate

Azure database for MySQL Flexible Server uses a public SSL CA certificate to connect. Placing the DigiCertGlobalRootCA.crt.pem in the prisma folder will help with authentication over SSL to work seamlessly.

MySQL connection string

Now you need to create a connection string in the following format for the Azure database for MySQL Flexible Server. When creating the server, you provided an admin username and password which you will use in the connection string. Note that SSL is enabled by default on Azure database for MySQL Flexible server and hence please use sslaccept=strict in the connection string. If you have disabled SSL on the server, you can remove it from the connection string.

mysql://<USERNAME>:<PLAIN_TEXT_PASSWORD>@<ACCESS_HOST_URL>/<DATABASE_NAME>?sslaccept=strict

Example

mysql://demoadminuser:[email protected]/products?sslaccept=strict

Add the connection string as environment variable in the Vercel project configuration

image

Push the schema into the database

Push the database schema to your Azure database for MySQL Flexible Server database products using Prisma.

npx prisma db push

Run the seed script to populate your database with Product and Category data.

npm run seed

Run the App

Run the app with following command:

npm run dev

Open your browser at localhost:3000 to see the running application.

Deploy your own

After you've got your application running locally, it's time to deploy it. Deploy the example using Vercel:

Deploy with Vercel

vercel-nextjs-app-azure-db-mysql's People

Contributors

mksuni avatar microsoftopensource avatar nitishsharma2825 avatar dependabot[bot] avatar microsoft-github-operations[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.