title | description | ms.topic | ms.date | ms.custom |
---|---|---|---|---|
Use JavaScript on Azure MySQL |
To create or move your MySQL database to Azure, you need a MySQL resource. |
include |
08/08/2022 |
devx-track-js, devx-track-azurecli |
You can create a resource with:
- Azure CLI
- Azure portal
- @azure/arm-mysql
[!INCLUDE Azure CLI commands]
While developing your MySQL database with JavaScript, use one of the following tools:
- Azure Cloud Shell's mysql CLI
- MySQL Workbench
- Visual Studio Code extension
The Azure MySQL uses npm packages already available, such as:
To connect and use your MySQL on Azure with JavaScript, use the following procedure.
Note
This article contains references to the term slave, a term that Microsoft no longer uses. When the term is removed from the software, we’ll remove it from this article.
-
Make sure Node.js and npm are installed.
-
Create a Node.js project in a new folder:
mkdir MySQLDemo && \ cd MySQLDemo && \ npm init -y && \ npm install promise-mysql && \ touch index.js && \ code .
The command:
- creates a project folder named
MySQLDemo
- changes the Bash terminal into that folder
- initializes the project, which creates the
package.json
file - installs the promise-mysql npm package - to use async/await
- creates the
index.js
script file - opens the project in Visual Studio Code
- creates a project folder named
-
Copy the following JavaScript code into
index.js
::::code language="JavaScript" source="~/../js-e2e/database/mysql/index.js" :::
-
Replace the host, user, and password with your values in the script for your connection configuration object,
config
. -
Run the script.