You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/mysql/single-server/connect-nodejs.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,18 +31,18 @@ This article assumes that you're familiar with developing using Node.js, but you
31
31
32
32
## Install Node.js and the MySQL connector
33
33
34
-
Depending on your platform, follow the instructions in the appropriate section to install [Node.js](https://nodejs.org). Use npm to install the [mysql](https://www.npmjs.com/package/mysql) package and its dependencies into your project folder.
34
+
Depending on your platform, follow the instructions in the appropriate section to install [Node.js](https://nodejs.org). Use npm to install the [mysql2](https://www.npmjs.com/package/mysql2) package and its dependencies into your project folder.
35
35
36
36
### [Windows](#tab/windows)
37
37
38
38
1. Visit the [Node.js downloads page](https://nodejs.org/en/download/), and then select your desired Windows installer option.
39
39
2. Make a local project folder such as `nodejsmysql`.
40
40
3. Open the command prompt, and then change directory into the project folder, such as `cd c:\nodejsmysql\`
41
-
4. Run the NPM tool to install the mysql library into the project folder.
41
+
4. Run the NPM tool to install the mysql2 library into the project folder.
42
42
43
43
```cmd
44
44
cd c:\nodejsmysql\
45
-
"C:\Program Files\nodejs\npm" install mysql
45
+
"C:\Program Files\nodejs\npm" install mysql2
46
46
"C:\Program Files\nodejs\npm" list
47
47
```
48
48
@@ -62,12 +62,12 @@ Depending on your platform, follow the instructions in the appropriate section t
62
62
sudo apt-get install -y nodejs
63
63
```
64
64
65
-
2. Run the following commands to create a project folder `mysqlnodejs` and install the mysql package into that folder.
65
+
2. Run the following commands to create a project folder `mysqlnodejs` and install the mysql2 package into that folder.
66
66
67
67
```bash
68
68
mkdir nodejsmysql
69
69
cd nodejsmysql
70
-
npm install --save mysql
70
+
npm install --save mysql2
71
71
npm list
72
72
```
73
73
@@ -90,12 +90,12 @@ Depending on your platform, follow the instructions in the appropriate section t
90
90
sudo yum install -y nodejs
91
91
```
92
92
93
-
1. Run the following commands to create a project folder `mysqlnodejs` and install the mysql package into that folder.
93
+
1. Run the following commands to create a project folder `mysqlnodejs` and install the mysql2 package into that folder.
94
94
95
95
```bash
96
96
mkdir nodejsmysql
97
97
cd nodejsmysql
98
-
npm install --save mysql
98
+
npm install --save mysql2
99
99
npm list
100
100
```
101
101
@@ -109,12 +109,12 @@ Depending on your platform, follow the instructions in the appropriate section t
109
109
sudo zypper install nodejs
110
110
```
111
111
112
-
1. Run the following commands to create a project folder `mysqlnodejs` and install the mysql package into that folder.
112
+
1. Run the following commands to create a project folder `mysqlnodejs` and install the mysql2 package into that folder.
113
113
114
114
```bash
115
115
mkdir nodejsmysql
116
116
cd nodejsmysql
117
-
npm install --save mysql
117
+
npm install --save mysql2
118
118
npm list
119
119
```
120
120
@@ -124,12 +124,12 @@ Depending on your platform, follow the instructions in the appropriate section t
124
124
125
125
1. Visit the [Node.js downloads page](https://nodejs.org/en/download/), and then select your macOS installer.
126
126
127
-
2. Run the following commands to create a project folder `mysqlnodejs` and install the mysql package into that folder.
127
+
2. Run the following commands to create a project folder `mysqlnodejs` and install the mysql2 package into that folder.
128
128
129
129
```bash
130
130
mkdir nodejsmysql
131
131
cd nodejsmysql
132
-
npm install --save mysql
132
+
npm install --save mysql2
133
133
npm list
134
134
```
135
135
@@ -165,10 +165,10 @@ Get the connection information needed to connect to the Azure Database for MySQL
165
165
166
166
Use the following code to connect and load the data by using **CREATE TABLE** and **INSERT INTO** SQL statements.
167
167
168
-
The [mysql.createConnection()](https://github.com/mysqljs/mysql#establishing-connections) method is used to interface with the MySQL server. The [connect()](https://github.com/mysqljs/mysql#establishing-connections) function is used to establish the connection to the server. The [query()](https://github.com/mysqljs/mysql#performing-queries) function is used to execute the SQL query against MySQL database.
168
+
The [mysql.createConnection()](https://github.com/sidorares/node-mysql2#first-query) method is used to interface with the MySQL server. The [connect()](https://github.com/sidorares/node-mysql2#first-query) function is used to establish the connection to the server. The [query()](https://github.com/sidorares/node-mysql2#first-query) function is used to execute the SQL query against MySQL database.
169
169
170
170
```javascript
171
-
constmysql=require('mysql');
171
+
constmysql=require('mysql2');
172
172
constfs=require('fs');
173
173
174
174
var config =
@@ -232,10 +232,10 @@ function queryDatabase(){
232
232
233
233
Use the following code to connect and read the data by using a **SELECT** SQL statement.
234
234
235
-
The [mysql.createConnection()](https://github.com/mysqljs/mysql#establishing-connections) method is used to interface with the MySQL server. The [connect()](https://github.com/mysqljs/mysql#establishing-connections) method is used to establish the connection to the server. The [query()](https://github.com/mysqljs/mysql#performing-queries) method is used to execute the SQL query against MySQL database. The results array is used to hold the results of the query.
235
+
The [mysql.createConnection()](https://github.com/sidorares/node-mysql2#first-query) method is used to interface with the MySQL server. The [connect()](https://github.com/sidorares/node-mysql2#first-query) method is used to establish the connection to the server. The [query()](https://github.com/sidorares/node-mysql2#first-query) method is used to execute the SQL query against MySQL database. The results array is used to hold the results of the query.
236
236
237
237
```javascript
238
-
constmysql=require('mysql');
238
+
constmysql=require('mysql2');
239
239
constfs=require('fs');
240
240
241
241
var config =
@@ -284,10 +284,10 @@ function readData(){
284
284
285
285
Use the following code to connect and update data by using an **UPDATE** SQL statement.
286
286
287
-
The [mysql.createConnection()](https://github.com/mysqljs/mysql#establishing-connections) method is used to interface with the MySQL server. The [connect()](https://github.com/mysqljs/mysql#establishing-connections) method is used to establish the connection to the server. The [query()](https://github.com/mysqljs/mysql#performing-queries) method is used to execute the SQL query against MySQL database.
287
+
The [mysql.createConnection()](https://github.com/sidorares/node-mysql2#first-query) method is used to interface with the MySQL server. The [connect()](https://github.com/sidorares/node-mysql2#first-query) method is used to establish the connection to the server. The [query()](https://github.com/sidorares/node-mysql2#first-query) method is used to execute the SQL query against MySQL database.
288
288
289
289
```javascript
290
-
constmysql=require('mysql');
290
+
constmysql=require('mysql2');
291
291
constfs=require('fs');
292
292
293
293
var config =
@@ -332,10 +332,10 @@ function updateData(){
332
332
333
333
Use the following code to connect and delete data by using a **DELETE** SQL statement.
334
334
335
-
The [mysql.createConnection()](https://github.com/mysqljs/mysql#establishing-connections) method is used to interface with the MySQL server. The [connect()](https://github.com/mysqljs/mysql#establishing-connections) method is used to establish the connection to the server. The [query()](https://github.com/mysqljs/mysql#performing-queries) method is used to execute the SQL query against MySQL database.
335
+
The [mysql.createConnection()](https://github.com/sidorares/node-mysql2#first-query) method is used to interface with the MySQL server. The [connect()](https://github.com/sidorares/node-mysql2#first-query) method is used to establish the connection to the server. The [query()](https://github.com/sidorares/node-mysql2#first-query) method is used to execute the SQL query against MySQL database.
0 commit comments