mysql

1. 登陆

mysql -u 用户名 -p

2. 启动mysql(本地通常关机后要重新启动才能登录)

mysql.server start

mysql.server stop

mysql.server restart

3. sequel pro 连接不上(授权)

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

4. navicat 如何数据同步

1⃣️ 保存该库数据到本地;选中该表,然后右键,选中“转存sql文件” =》 “数据加结构”

2⃣️ 选择要选中的数据库,右键“运行sql文件”

5 group by

select 列名1,列名2,count(1) as count 
from 表名
group by  列名1,列名2 
having count>1  and 其他条件

//注意这里的列名1,列名2要互相对应匹配(包括数量)
//原理:先按照要查询出现重复数据的列,进行分组查询。count > 1 代表出现 2 次或 2 次以上。

6 如何导出数据到execl表或者对着那个表(右键导出向导)

select * from table into outfile '/data/web_publish/test/xls' fields terminated by ',' optionally enclosed by '"' lines terminated by '
';

如果报错"ERROR 1290 (HY000): .. MySQL server running with –secure-file-priv option"

https://blog.csdn.net/fdipzone/article/details/78634992(解决方法和参数说明);

通过找到对应的配置文件

find / -name my.conf  

然后添加重启动就行

还有另外一种形式

mysql -u echo -P 3306 -h ip -p web_activity -e 'select * from table'>/data/web_publish/lynn.xls

7. 悲观锁和乐观锁 (https://juejin.im/post/6844903807520866317

悲观锁:(排他锁)

1⃣️ 产生条件(排他锁):  insert、update、delete都会参数悲观锁,默认select不会产生悲观锁,但是如果select * for update; 那也会产生悲观锁;
2⃣️ 作用: 不会影响其他事务的select操作(获取的还是未更新的数据);但是对insert、update、delete、select * for update等操作,则必须等待上一条insert执行完成
3⃣️ 作用的行数:所有符合查询的行数,比如有where  id = 1,那只会影响id等于1的行数

#Sequelize 写法

await Accounts.findOne({
    where: { name: 'HelKyle' },
    lock: Sequelize.Transaction.LOCK.UPDATE
});

await Accounts.findOne({
    where: { name: 'HelKyle' },
    lock: Sequelize.Transaction.LOCK.SHARE
});

乐观锁:在update前先比对版本号是不是和前面select的一致;不是则update失败(常用于订单状态更新)

在db 表里面加一个版本号或者是时间戳,写之前先查。最后以版本号或者是时间戳作为条件来更新。版本号就是update ...,set version+1 where version=xxx.时间戳就是update ... set time=now() where time=xxxx

update xxx set send_status = 1 where send_status = 0

其他:

sequelize使用

1⃣️ 采用批量插入

Model.bulkCreate([{}, {}])
原文地址:https://www.cnblogs.com/luguiqing/p/12046371.html