This tutorial includes a free MySQL database with all the necessary database tables and columns for a typical eCommerce website. This is provided for any web developer - novice or advanced - to leverage as a starting point in their production process. This tutorial also includes steps to import this database (or any.sql file) locally or remotely. You will note that as you type the database name, two additional files will be created automatically: the Data and the Log file. The data file houses all of the data in your database, while the log file tracks changes to the database. Click OK to create the database. You will see your new database appear in the expanded Database folder. In this quickstart, you connect to an Azure Database for MySQL by using Node.js. You then use SQL statements to query, insert, update, and delete data in the database from Mac, Ubuntu Linux, and Windows platforms. This topic assumes that you're familiar with developing using Node.js, but you're new to working with Azure Database for MySQL.
The package is located inside a disk image (.dmg
) file that you first need to mount by double-clicking its icon in the Finder. It should then mount the image and display its contents.
Before proceeding with the installation, be sure to stop all running MySQL server instances by using either the MySQL Manager Application (on macOS Server), the preference pane, or mysqladmin shutdown on the command line.
To install MySQL using the package installer:
Download the disk image (
.dmg
) file (the community version is available here) that contains the MySQL package installer. Double-click the file to mount the disk image and see its contents.Figure 2.1 MySQL Package Installer: DMG Contents
Double-click the MySQL installer package from the disk. It is named according to the version of MySQL you have downloaded. For example, for MySQL server 5.7.35 it might be named
mysql-5.7.35-osx-
.10.13-x86_64
.pkgThe initial wizard introduction screen references the MySQL server version to install. Click to begin the installation.
Figure 2.2 MySQL Package Installer Wizard: Introduction
The MySQL community edition shows a copy of the relevant GNU General Public License. Click and then to continue.
From the Installation Type page you can either click to execute the installation wizard using all defaults, click to alter which components to install (MySQL server, Preference Pane, Launchd Support -- all enabled by default).
Although the option is visible, the installation location cannot be changed.
Figure 2.3 MySQL Package Installer Wizard: Installation Type
Figure 2.4 MySQL Package Installer Wizard: Customize
Click to begin the installation process.
After a successful installation, the installer displays a window with your temporary root password. This cannot be recovered so you must save this password for the initial login to MySQL. For example:
Figure 2.5 MySQL Package Installer Wizard: Temporary Root Password
MySQL expires this temporary root password after the initial login and requires you to create a new password.
Summary is the final step and references a successful and complete MySQL Server installation. the wizard.
MySQL server is now installed, but it is not loaded (or started) by default. Use either launchctl from the command line, or start MySQL by clicking 'Start' using the MySQL preference pane. For additional information, see Chapter 3, Installing a MySQL Launch Daemon, and Chapter 4, Installing and Using the MySQL Preference Pane. Use the MySQL Preference Pane or launchd to configure MySQL to automatically start at bootup.
When installing using the package installer, the files are installed into a directory within /usr/local
matching the name of the installation version and platform. For example, the installer file mysql-5.7.35-
installs MySQL into osx10.13-x86_64.dmg
/usr/local/mysql-5.7.35-osx10.13-x86_64/
. The following table shows the layout of the installation directory.
Table 2.1 MySQL Installation Layout on macOS
Directory | Contents of Directory |
---|---|
bin | mysqld server, client and utility programs |
data | Log files, databases |
docs | Helper documents, like the Release Notes and build information |
include | Include (header) files |
lib | Libraries |
man | Unix manual pages |
mysql-test | MySQL test suite |
share | Miscellaneous support files, including error messages, sample configuration files, SQL for database installation |
support-files | Scripts and sample configuration files |
/tmp/mysql.sock | Location of the MySQL Unix socket |
During the package installer process, a symbolic link from /usr/local/mysql
to the version/platform specific directory created during installation is created automatically.
In this quickstart, you connect to an Azure Database for MySQL by using Node.js. You then use SQL statements to query, insert, update, and delete data in the database from Mac, Ubuntu Linux, and Windows platforms.
This topic assumes that you're familiar with developing using Node.js, but you're new to working with Azure Database for MySQL.
Prerequisites
- An Azure account with an active subscription. Create an account for free.
- An Azure Database for MySQL server. Create an Azure Database for MySQL server using Azure portal or Create an Azure Database for MySQL server using Azure CLI.
Important

Ensure the IP address you're connecting from has been added the server's firewall rules using the Azure portal or Azure CLI
Install Node.js and the MySQL connector
Depending on your platform, follow the instructions in the appropriate section to install Node.js. Use npm to install the mysql package and its dependencies into your project folder.
Windows
Visit the Node.js downloads page, and then select your desired Windows installer option.
Make a local project folder such as
nodejsmysql
.Open the command prompt, and then change directory into the project folder, such as
cd c:nodejsmysql
Run the NPM tool to install the mysql library into the project folder.
Verify the installation by checking the
npm list
output text. The version number may vary as new patches are released.
Linux (Ubuntu)
Run the following commands to install Node.js and npm the package manager for Node.js.
Run the following commands to create a project folder
mysqlnodejs
and install the mysql package into that folder.Verify the installation by checking npm list output text. The version number may vary as new patches are released.
macOS
Visit the Node.js downloads page, and then select your macOS installer.
Run the following commands to create a project folder
mysqlnodejs
and install the mysql package into that folder.Verify the installation by checking the
npm list
output text. The version number may vary as new patches are released.
Get connection information
Get the connection information needed to connect to the Azure Database for MySQL. You need the fully qualified server name and login credentials.
- Log in to the Azure portal.
- From the left-hand menu in Azure portal, select All resources, and then search for the server you have created (such as mydemoserver).
- Select the server name.
- From the server's Overview panel, make a note of the Server name and Server admin login name. If you forget your password, you can also reset the password from this panel.
Running the JavaScript code in Node.js
- Paste the JavaScript code into text files, and then save it into a project folder with file extension .js (such as C:nodejsmysqlcreatetable.js or /home/username/nodejsmysql/createtable.js).
- Open the command prompt or bash shell, and then change directory into your project folder
cd nodejsmysql
. - To run the application, enter the node command followed by the file name, such as
node createtable.js
. - On Windows, if the node application is not in your environment variable path, you may need to use the full path to launch the node application, such as
'C:Program Filesnodejsnode.exe' createtable.js
Connect, create table, and insert data
Use the following code to connect and load the data by using CREATE TABLE and INSERT INTO SQL statements.
The mysql.createConnection() method is used to interface with the MySQL server. The connect() function is used to establish the connection to the server. The query() function is used to execute the SQL query against MySQL database. Upgrade mac os from yosemite to sierra.
Replace the host
, user
, password
, and database
parameters with the values that you specified when you created the server and database.
Read data
Use the following code to connect and read the data by using a SELECT SQL statement.
The mysql.createConnection() method is used to interface with the MySQL server. The connect() method is used to establish the connection to the server. The query() method is used to execute the SQL query against MySQL database. The results array is used to hold the results of the query.
Replace the host
, user
, password
, and database
parameters with the values that you specified when you created the server and database.
Update data
Use the following code to connect and read the data by using an UPDATE SQL statement.

The mysql.createConnection() method is used to interface with the MySQL server. The connect() method is used to establish the connection to the server. The query() method is used to execute the SQL query against MySQL database.
Replace the host
, user
, password
, and database
parameters with the values that you specified when you created the server and database.
Delete data
Use the following code to connect and read the data by using a DELETE SQL statement.
The mysql.createConnection() method is used to interface with the MySQL server. The connect() method is used to establish the connection to the server. The query() method is used to execute the SQL query against MySQL database.
Replace the host
, user
, password
, and database
parameters with the values that you specified when you created the server and database.
Clean up resources
To clean up all resources used during this quickstart, delete the resource group using the following command:
Create Mysql Database On Local Machine
Next steps
