Create Local Mysql Database Mac



  1. 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.
  2. Mysql -u root -p'root' -h 127.0.0.1 -P 3306 -D local no space after -p as specified in the documentation It will take you to the mysql console directly by switching to the mentioned database.

A database in MySQL is implemented as a directory containing files that correspond to tables in the database. Because there are no tables in a database when it is initially created, the CREATE DATABASE statement creates only a directory under the MySQL data directory. 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.

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

  1. Visit the Node.js downloads page, and then select your desired Windows installer option.

  2. Make a local project folder such as nodejsmysql.

  3. Open the command prompt, and then change directory into the project folder, such as cd c:nodejsmysql

  4. Run the NPM tool to install the mysql library into the project folder.

  5. Verify the installation by checking the npm list output text. The version number may vary as new patches are released.

Linux (Ubuntu)

  1. Run the following commands to install Node.js and npm the package manager for Node.js.

  2. Run the following commands to create a project folder mysqlnodejs and install the mysql package into that folder.

  3. Verify the installation by checking npm list output text. The version number may vary as new patches are released.

macOS

  1. Visit the Node.js downloads page, and then select your macOS installer.

  2. Run the following commands to create a project folder mysqlnodejs and install the mysql package into that folder.

  3. 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.

Mysql
  1. Log in to the Azure portal.
  2. From the left-hand menu in Azure portal, select All resources, and then search for the server you have created (such as mydemoserver).
  3. Select the server name.
  4. 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

  1. 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).
  2. Open the command prompt or bash shell, and then change directory into your project folder cd nodejsmysql.
  3. To run the application, enter the node command followed by the file name, such as node createtable.js.
  4. 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.

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.

Create Mysql Database On Local Machine

Clean up resources

Create Local Mysql Database Mac Os

To clean up all resources used during this quickstart, delete the resource group using the following command:

Create Local Mysql Database Macro

Next steps