MyISAM

2019.12月份总结

佐手、 提交于 2019-12-08 07:17:21
关于数据库的index要重点总结一下,包括聚簇索引和非聚簇索引。本次没有总结好。 还有联合索引等。 聚簇索引:将数据存储与索引放到了一块,找到索引也就找到了数据 非聚簇索引:将数据存储于索引分开结构,索引结构的叶子节点指向了数据的对应行,myisam通过key_buffer把索引先缓存到内存中,当需要访问数据时(通过索引访问数据),在内存中直接搜索索引,然后通过索引找到磁盘相应数据,这也就是为什么索引不在key buffer命中时,速度慢的原因 关于锁 ThreadLocal 为每个使用该变量的线程提供独立的变量副本,所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的副本。 ThreadLocal 的经典使用场景是数据库连接和 session 管理等。 3.说一下 synchronized 底层实现原理? synchronized 是由一对 monitorenter/monitorexit 指令实现的,monitor 对象是同步的基本实现单元。在 Java 6 之前,monitor 的实现完全是依靠操作系统内部的互斥锁,因为需要进行用户态到内核态的切换,所以同步操作是一个无差别的重量级操作,性能也很低。但在 Java 6 的时候,Java 虚拟机 对此进行了大刀阔斧地改进,提供了三种不同的 monitor 实现,也就是常说的三种不同的锁:偏向锁(Biased

~150ms on a 2 million rows MySQL MyISAM table

半世苍凉 提交于 2019-12-08 04:11:30
问题 I'm learning about MySQL performance with a pet project consisting of ~2million rows + ~600k rows (two MyISAM tables). A range query using BETWEEN on two INT(10) indexed columns, LIMITed to 1 returned result takes about 160ms (including an INNER JOIN). I figure my configuration isn't optimised and am looking for some advice on how to either diagnose, or perhaps "common configuration". I created a gist containing both tables, the query and the contents of my.cnf. I created the b-tree index

MyISAM Engine table relations (MySQL)

心不动则不痛 提交于 2019-12-08 03:38:09
问题 I’m using a host which only supports MyISAM tables engines for MySQL. I’m trying to create a CMS using php and MySQL, however, I’m having issues working out how to create relationships between the tables. For example, one of the features within this system is being able to assign tags to an article/blogpost, similar to how stack overflow has tags on their questions. My question is, as I cannot change my tables to use InnoDB, how can I form a relationship between the two tables? I am unable to

mysql锁知识小了解

[亡魂溺海] 提交于 2019-12-07 17:41:20
一、概述 mysql的锁分为表锁和行锁两种,其中myisam引擎用的是表锁, innoDB默认的使用是行锁, 其他情况是表锁。 两种锁的优缺点: 表级锁:加锁速度快,开销小。不会出现死锁的情况,粒度大,发生锁冲突的概率最高,并发度最低。 行级锁:加锁速度慢,开销大。 会出现死锁的情况,粒度小, 发生锁冲突的概率最小,并发度最高 页面锁:介于以上两者之间 无法确定哪种锁更合适: 表级锁更适合查询为主,只有少量按索引更新数据的应用,如web应用。 行级锁适合有大量索引并发更新少量不同的数据,同时有并发查询的应用,如一些在线的事物系统。 二、MyIsam存储引擎 只支持表锁。 查询表级锁的争用情况: table_locks_waited 和 table_locks_immediate 1. mysql> show status like 'table%'; 2. +-----------------------+-------+ 3. | Variable_name | Value | 4. +-----------------------+-------+ 5. | Table_locks_immediate | 2979 | 6. | Table_locks_waited | 0 | 2.1、表级锁的锁模式 两种模式:表共享读锁,表独占写锁 分析:

MySQL大表优化方案

☆樱花仙子☆ 提交于 2019-12-07 15:07:34
当MySQL单表记录数过大时,增删改查性能都会急剧下降,可以参考以下步骤来优化: 单表优化 除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑、部署、运维的各种复杂度,一般以整型值为主的表在 千万级 以下,字符串为主的表在 五百万 以下是没有太大问题的。而事实上很多时候MySQL单表的性能依然有不少优化空间,甚至能正常支撑千万级以上的数据量: 字段 尽量使用 TINYINT 、 SMALLINT 、 MEDIUM_INT 作为整数类型而非 INT ,如果非负则加上 UNSIGNED VARCHAR 的长度只分配真正需要的空间 使用枚举或整数代替字符串类型 尽量使用 TIMESTAMP 而非 DATETIME , 单表不要有太多字段,建议在20以内 避免使用NULL字段,很难查询优化且占用额外索引空间 用整型来存IP 索引 索引并不是越多越好,要根据查询有针对性的创建,考虑在 WHERE 和 ORDER BY 命令上涉及的列建立索引,可根据 EXPLAIN 来查看是否用了索引还是全表扫描 应尽量避免在 WHERE 子句中对字段进行 NULL 值判断,否则将导致引擎放弃使用索引而进行全表扫描 值分布很稀少的字段不适合建索引,例如"性别"这种只有两三个值的字段 字符字段只建前缀索引 字符字段最好不要做主键 不用外键,由程序保证约束 尽量不用 UNIQUE

《2019年小米春季上海 PHP 实习生招聘面试题》部分答案解析

南笙酒味 提交于 2019-12-07 15:05:33
1 丶 Nginx 怎么实现负载均衡 这个还是比较简单 1.轮询 这种是默认的策略,把每个请求按顺序逐一分配到不同的 server,如果 server 挂掉,能自动剔除。 2.最少连接 把请求分配到连接数最少的 server 3.权重 使用 weight 来指定 server 访问比率,weight 默认是 1。以下配置会是 server2 访问的比例是 server1 的两倍。 4.ip_hash 每个请求会按照访问 ip 的 hash 值分配,这样同一客户端连续的 Web 请求都会被分发到同一 server 进行处理,可以解决 session 的问题。如果 server 挂掉,能自动剔除。 ip_hash 可以和 weight 结合使用。 2 丶 Linux 常用的命令 这个就不多说了 3 丶微信小程序常用的组件 view 丶 text 丶 button 丶 navigator 丶 scroll-view...... 等等 4 丶 Nginx 怎么配置虚拟主机 恩 2333333 5 丶 TP5 和 Laravel 框架差异 恩 2333333 6 丶 TP5 和 Laravel 框架中的数据迁移 这个本社区就有文档的 7 丶 RBAC 模型的讲解 什么是 RBAC RBAC (基于角色的访问控制):英文名称 Rose base Access Controller

MySQL Backup: Can I copying individual MyISAM table files to another server with different MySQL version and different OS?

你离开我真会死。 提交于 2019-12-07 12:20:51
问题 I means copying individual MyISAM table files is: (shut down mysqld and copy the .frm, .myd, and .myi files from one database folder to another) Question: (a) can I use this way to backup MySQL database folder from one server to another server with different MySQL version? (b) can this backup files moved to different OS? (example: debian to centos) 回答1: Only file-level copy MyISAM tables between versions of servers with the same: - CPU 'endian' ( SPARC != x86 ) - MySQL versions are upgrade

mySql搜索引擎

落爺英雄遲暮 提交于 2019-12-07 10:33:44
转载自 深入浅出mysql数据库 MySQL5.5以后默认使用 InnoDB 存储引擎,其中InnoDB和BDB提供事务安全表,其它存储引擎都是非事务安全表。 若要修改默认引擎,可以修改配置文件中的default-storage-engine。可以通过:show variables like ‘default_storage_engine’;查看当前数据库到默认引擎。命令:show engines和show variables like ‘have%’可以列出当前数据库所支持到引擎。其中Value显示为disabled的记录表示数据库支持此引擎,而在数据库启动时被禁用。在MySQL5.1以后,INFORMATION_SCHEMA数据库中存在一个ENGINES的表,它提供的信息与show engines;语句完全一样,可以使用下面语句来查询哪些存储引擎支持事物处理:select engine from information_chema.engines where transactions = ‘yes’; 可以通过engine关键字在创建或修改数据库时指定所使用到引擎。 主要存储引擎:MyISAM、InnoDB、MEMORY和MERGE介绍: 在创建表到时候通过engine=…或type=…来指定所要使用到引擎。show table status from

What is maximum records quantity a MySQL table can store?

旧时模样 提交于 2019-12-07 05:38:45
问题 How many records can a MySQL MyISAM table store? How many InnoDB can? 回答1: You can't count by number of records because your table can have really short records with only a few int fields or your records might be really long with hundreds of fields. So it has to be measured in the file size of the tables. For MYSQL: The table size limit is based on the operating system drive file system that MySQL is installed on, ranging from 2GB to 2TB. See the MySQL reference manual for full explanations

MyISAM unique keys being cut off at 64 bytes, causing collisions

老子叫甜甜 提交于 2019-12-07 05:11:08
问题 I've got a MySQL table that stores urls as unique keys. I'm starting to get collisions on my keys because it seems the keys themselves are only the first 64 bytes (or characters if you prefer, its a latin-1 collated) of any url. So if a url is over 64 characters and I've already got a similar url it throws an error. For example: SELECT l.link_id FROM mydb.links l WHERE url = 'http://etonline.com/tv/108475_Charlie_Sheen_The_People_Have_Elected_Me_as_Their_Leader/index.html' Throws this error: