How to install the mysql module in nodejs: 1. Open the cmd window and execute the "npm install -g cnpm" command to install the cnpm tool; 2. Use the cd command to enter the project directory and execute "cnpm install mysql" in the project command to install the MySQL module.
The operating environment of this tutorial: windows7 system, nodejs version 12.19.0, Dell G3 computer.
node installation and configuration Mysql module
①Install Mysql module
cmd install Taobao image
npm install -g cnpm
Enter the project directory and install the MySQL module in the project
cnpm install mysql
②. Configure environment variables
Add C:\Program Files\MySQL\MySQL Server 8.0\bin
to the environment variables. The variable name can be arbitrary. For example, mysql_home
variable value is C:\Program Files\MySQL\MySQL Server 8.0\bin
③. Error report
Client does not support authentication protocol requested by server
1. Enter the decompressed mysql root directory through the command line (C:\Program Files\MySQL\MySQL Server 8.0\bin
)Down.
2. Log in to the database
mysql -u root -p
3. Enter the root password
Enter password: ******
4. Change the encryption method
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
5. Change the password: In this example 123456 is the new password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
6. Refresh:
mysql> FLUSH PRIVILEGES;
④.js file format
var mysql = require('mysql');//引用Mysql var connection = mysql.createConnection({//配置连接 host: 'localhost',//数据库地址 user : "xxx",//数据库用户 password: "xxx",//数据库密码 database : "world"//需要连接的数据库 }); connection.connect();//连接数据库 connection.query('select * from city',function(err,rows,fields){//执行sql语句 if(err) throw err ; console.log('thesolution is:' ,rows[0]); }); connection.end();//断开连接
[Recommended learning: "nodejs tutorial"]
The above is the detailed content of How to install mysql module in nodejs. For more information, please follow other related articles on the PHP Chinese website!

Vercel是什么?本篇文章带大家了解一下Vercel,并介绍一下在Vercel中部署 Node 服务的方法,希望对大家有所帮助!

gm是基于node.js的图片处理插件,它封装了图片处理工具GraphicsMagick(GM)和ImageMagick(IM),可使用spawn的方式调用。gm插件不是node默认安装的,需执行“npm install gm -S”进行安装才可使用。

大家都知道 Node.js 是单线程的,却不知它也提供了多进(线)程模块来加速处理一些特殊任务,本文便带领大家了解下 Node.js 的多进(线)程,希望对大家有所帮助!

今天跟大家介绍一个最新开源的 javaScript 运行时:Bun.js。比 Node.js 快三倍,新 JavaScript 运行时 Bun 火了!

node怎么爬取数据?下面本篇文章给大家分享一个node爬虫实例,聊聊利用node抓取小说章节的方法,希望对大家有所帮助!

在nodejs中,lts是长期支持的意思,是“Long Time Support”的缩写;Node有奇数版本和偶数版本两条发布流程线,当一个奇数版本发布后,最近的一个偶数版本会立即进入LTS维护计划,一直持续18个月,在之后会有12个月的延长维护期,lts期间可以支持“bug fix”变更。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
