SELECT * FROM users WHERE uname in (‘zs’,‘ls’)
- 排序
order by 要写在 sql 语句的最后
– asc 升序 desc 降序
SELECT * FROM users ORDER BY DESC
SELECT * FROM users WHERE uage > 18 ORDER by desc
- 限制查询条数
– 取前3条数据
SELECT * FROM users LIMIT 3
– 降序后去3条数据
SELECT * FROM users ORDER BY DESC LIMIT 3
– 跳过3条,取2条
SELECT * FROM users ORDER BY DESC LIMIT 3,2
- 获取总条数
SELECT COUNT(*) FROM users
- 表连接
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
Node.js 中操作 MySQL
使用 mysql 第三方包
https://github.com/mysqljs/mysql
安装
npm install mysql
Hello World
var mysql = require(‘mysql’);
var connection = mysql.createConnection({
host : ‘localhost’,
user : ‘me’,
password : ‘secret’,
database : ‘my_db’
});
connection.connect();
connection.query(‘SELECT 1 + 1 AS solution’, function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
connection.end();
增删改查
查询
基本查询:
connection.query(‘SELECT * FROM books
WHERE author
= “David”’, function (error, results, fields) {
// error will be an Error if one occurred during the query
// results will contain the results of the query
// fields will contain information about the returned results fields (if any)
});
条件查询:
connection.query(‘SELECT * FROM books
WHERE author
= ?’, [‘David’], function (error, results, fields) {
// error will be an Error if one occurred during the query
// results will contain the results of the query
// fields will contain information about the returned results fields (if any)
});
添加
var post = {id: 1, title: ‘Hello MySQL’};
var query = connection.query(‘INSERT INTO posts SET ?’, post, function (error, results, fields) {
if (error) throw error;
// Neat!
});
console.log(query.sql); // INSERT INTO posts SET id
= 1, title
= ‘Hello MySQL’
删除
connection.query(‘DELETE FROM posts WHERE title = “wrong”’, function (error, results, fields) {
if (error) throw error;
console.log(‘deleted ’ + results.affectedRows + ’ rows’);
})
修改
connection.query(‘UPDATE users SET foo = ?, bar = ?, baz = ? WHERE id = ?’, [‘a’, ‘b’, ‘c’, userId], function (error, results, fields) {
if (error) throw error;
// …
})
封装 dbHelper.js
const mysql = require(‘mysql’);
var connection = mysql.createConnection({
host : ‘localhost’,
port : 3306,
user : ‘root’,
password : ‘root’,
database : ‘guestbook’
});
exports.query = (sql, params, callback) => {
connection.connect();
connection.query(sql, params, function (error, results, fields) {
小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Java工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频文章来源:https://www.toymoban.com/news/detail-850545.html
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**
[外链图片转存中…(img-H9D6pyJw-1710834473844)]
[外链图片转存中…(img-dyitrzrG-1710834473845)]
[外链图片转存中…(img-ctTvypSE-1710834473845)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
[外链图片转存中…(img-dczdOvyk-1710834473845)]文章来源地址https://www.toymoban.com/news/detail-850545.html
到了这里,关于MySQL 的服务器安装及使用,springboot源码深度解析pdf的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!