随笔分类 -  数据库

摘要:MySQL - 性能优化 1. innodb_io_capacity(来自MySQL45讲第12讲) 1.1 查询 1.2 最好设置成磁盘的IOPS,获取IOPS命令如下 2. 查询脏页比例(来自MySQL45讲第12讲) 3. 重建表(来自MySQL45讲第13讲) MySQL - 性能优化 1. 阅读全文
posted @ 2022-01-08 08:54 Rocin 阅读(241) 评论(0) 推荐(0)
摘要:奇怪的现象 表结构 原因 解决方法 奇怪的现象(来自MySQL45讲第8章思考题) 当前隔离级别为可重复读 复现过程: 有A、B两个事务 B先执行了语句,并且马上commit begin; update t set c = 0 where id = c; commit; A执行了语句,但是没有com 阅读全文
posted @ 2021-12-17 15:00 Rocin 阅读(60) 评论(0) 推荐(0)
摘要:定义 相关命令 找出当前session或者global的隔离级别 设置当前session的隔离级别命令 定义 对于可重复读(repeatable read),查询只承认在事务启动前就已经commit的数据; 对于读提交(read committed),查询只承认在语句启动前就已经commit的数据; 阅读全文
posted @ 2021-12-17 14:57 Rocin 阅读(131) 评论(0) 推荐(0)
摘要:方法1 pymongo。使用$convert, MongoDB版本 >= 4,速度快。 # 假设{'age': '47'}, 转换后为{'age': 47} import time import pymongo start_time = time.time() handler = pymongo.M 阅读全文
posted @ 2019-08-31 22:54 Rocin 阅读(4226) 评论(0) 推荐(0)
摘要:参考 "offical doc" "medium" Mongo roles说明 https://docs.mongodb.com/manual/reference/built in roles/ userAdmin 阅读全文
posted @ 2018-11-06 14:32 Rocin 阅读(398) 评论(0) 推荐(0)
摘要:转: https://www.howtoing.com/how to move a postgresql data directory to a new location on ubuntu 16 04 阅读全文
posted @ 2018-11-06 14:30 Rocin 阅读(733) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1310818/201810/1310818-20181007114025306-1449888720.jpg) 阅读全文
posted @ 2018-10-07 11:41 Rocin 阅读(102) 评论(0) 推荐(0)
摘要:```python import pymongo import re client = pymongo.MongoClient('127.0.0.1', 27017) db_name = 'Trade' db = client[db_name] filter1 = {'$or':[{"phone": {'$ne':""}}, {"cell_phone": {'$ne':""}}]} fil... 阅读全文
posted @ 2018-09-03 19:08 Rocin 阅读(2769) 评论(0) 推荐(0)
摘要:问题来源 在pycharm发现Create new schema的效果和新建数据库一样,所以产生这个问题 参考 https://stackoverflow.com/questions/11618277/difference between schema database in mysql 答案 在M 阅读全文
posted @ 2018-07-02 19:52 Rocin 阅读(897) 评论(0) 推荐(0)
摘要:运行 1. mongod dbpath (mongod is the "Mongo Daemon") 2. 在shell用mongo或者用studio 3t可视化连接 创建用户 阅读全文
posted @ 2018-06-22 22:49 Rocin 阅读(85) 评论(0) 推荐(0)
摘要:一对多关系、多对一关系和一对一关系 1. 至少都有一侧是单个实体,所以记录之间的联系通过外键实现,让外键指向这个实体。 2. 实现这种关系时,要在“多”这一侧加入一个外键,指向“一”这一侧联接的记录。 多对多关系 1. 解决方法是添加第三个表,这个表称为关联表。 2. 多对多关系可以分解成原表和关联 阅读全文
posted @ 2018-05-30 18:07 Rocin 阅读(2663) 评论(0) 推荐(0)
摘要:1. Flask SQLAlchemy 1.1 参考: http://flask sqlalchemy.pocoo.org/2.3/ https://github.com/janetat/flasky/commits/master?after=f0d6546112480b0f728194982e3f 阅读全文
posted @ 2018-05-21 13:54 Rocin 阅读(157) 评论(0) 推荐(0)
摘要:1. 概念 1. 目标:类/对象操作 SQL语句 DB API 再在数据库中执行。ORM做前两部,因为ORM本身无法操作数据库。参考:https://baike.baidu.com/item/ORM/3583252?fr=aladdin 2. 本质:类(class Users)对应数据库的表,类中的 阅读全文
posted @ 2018-05-19 12:36 Rocin 阅读(294) 评论(0) 推荐(0)
摘要:1. Web框架数据库相关 1.1 Django django ORM (ORM模块里调用pymysql/MySQLdb模块) 1.2 Flask/其他: 1.2.1 原生SQL pymysql(2/3) MySQLdb(2) 1.2.2 SQLAchemy(ORM) (ORM模块里调用pymysq 阅读全文
posted @ 2018-05-15 15:49 Rocin 阅读(167) 评论(0) 推荐(0)
摘要:``` 1. 打开/etc/mysql/debian.cnf文件,在这个文件中有系统默认给我们分配的用户名和密码,通过这个密码就可以直接对MySQL进行操作了。 2. 以debian-sys-maint为用户名登录,密码就是debian.cnf里那个。使用mysql -u debian-sys-maint -p 进行登录。 3. 进入mysql之后修改MySQL的密码,具体的操作如下用命令:set... 阅读全文
posted @ 2018-04-22 00:48 Rocin 阅读(2697) 评论(0) 推荐(0)
摘要:``` 1. 在Windows上,安装时请选择UTF-8编码,以便正确地处理中文。 在Mac或Linux上,需要编辑MySQL的配置文件,把数据库默认的编码全部改为UTF-8。MySQL的配置文件默认存放在/etc/my.cnf或者/etc/mysql/my.cnf: [client] default-character-set = utf8 [mysqld] default-storage-e... 阅读全文
posted @ 2018-04-22 00:47 Rocin 阅读(1734) 评论(0) 推荐(0)