https://www.jianshu.com/p/9b338095cbe8
node.js + mysql environment to build
0x01 Foreword
With the development of html web technology, and the needs of full-stack development for staff in terms of front-end, back-end basics has become a required course. In this section I will discuss about sharing windows
at node
+ mysql
build process.
download link:
0x02 download and install mysql, and configure
Reference Documents
1. Download mysql
2. Initialize mysql
- My.ini configuration
decompress after the download is complete, enter the main directory, create a new my.ini file and configure the following:
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 [mysqld] # 设置3306端口 port = 3306 # 设置mysql的安装目录 basedir=F:\\mysql\\mysql-8.0.15-winx64 # 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错 # datadir=F:\\mysql\\sqldata # 允许最大连接数 max_connections=20 # 服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB
- Initialization mysql
administrator mode open cmd, go to the bin directory, execute: - Installation mysqld
mysqld install
Wait occur successfully words
mysqld --initialize --console
Wait is finished, there will be the word password to remember later use.
If this step is not accidentally press to ctrl+c
cancel, you can delete the home directory data file, after the re-operation can be.
- Start mysql service
net start mysql
Wait for the start success words.
At this point, mysql initialization been completed.
3. Modify login and password
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
0x03 view the database
1. Command Line
show databases
2. Visualization Tools
Installation mysql native visible operation
0x04 mysql common commands
show databases
- Switching Database
user test
- Display table
show tables
- increase
insert into `user` (id, name, psw) values (null, 'name', 'psw');
- delete
DELETE FROM `user` WHERE id = 2
- change
update `user` SET psw = '52she' WHERE id = 1
- check
select * from user(表);
0x05 node used mysql
Mysql module introduced
- cmd
cnpm
ornpm
mountingmysql
module
cnpm install mysql
- Referenced in the project
require 'mysql'
At this point you can easily use the API provided by operating mysql database mysql.
Examples 0x06
var mysql = require('mysql'); var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: '52Zllshizhu', database: 'mytest' }); connection.connect(); insert(); function insert() { connection.query("INSERT INTO `user` (id, name, psw) VALUES (null, '靳建奇', '52Alsdkfj')", function(error, results, fields) { if(!error) console.log('insert : OK' ); }) selectAll(); } function selectAll() { connection.query('SELECT * FROM `user`', function(error, results, fields) { console.log(results); }) }