MySQL面试52道经典题目
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">公众号:尤而小屋</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">编辑:Peter</p>作者:caokegege
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">大众</span>好,我是Peter~</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">今天给<span style="color: black;">大众</span>分享一份MySQL面试的52道经典题目,<span style="color: black;">意见</span><span style="color: black;">保藏</span>~</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">1.Mysql中有哪几种锁?</span></span></h2><span style="color: black;">表级锁:开销小,加锁快;不会<span style="color: black;">显现</span>死锁;锁定粒度大,<span style="color: black;">出现</span>锁冲突的概率最高,并发度最低。</span><span style="color: black;">行级锁:开销大,加锁慢;会<span style="color: black;">显现</span>死锁;锁定粒度最小,<span style="color: black;">出现</span>锁冲突的概率最低,并发度<span style="color: black;">亦</span>最高。</span><span style="color: black;">页面锁:开销和加锁时间界于表锁和行锁之间;会<span style="color: black;">显现</span>死锁;锁定粒度界于表锁和行锁之间,并发度<span style="color: black;">通常</span>。</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">2.Mysql中有<span style="color: black;">那些</span><span style="color: black;">区别</span>的表类型?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">BDB、HEAP、ISAM、MERGE、MyISAM、InnoDB以及Gemeni,总共7种Mysql表类型</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">3.简述在MySQL数据库中MyISAM和InnoDB的区别</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">MyISAM:</span></p><span style="color: black;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">不支持事务,<span style="color: black;">然则</span>每次<span style="color: black;">查找</span>都是原子的;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">支持表级锁,即每次操作是对<span style="color: black;">全部</span>表加锁;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">存储表的总行数;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">一个MYISAM表有三个文件:索引文件、表结构文件、数据文件;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">采用非聚集索引,索引文件的数据域存储指向数据文件的指针。辅索引与主索引基本一致,<span style="color: black;">然则</span>辅索引<span style="color: black;">不消</span><span style="color: black;">保准</span><span style="color: black;">独一</span>性。</p>
</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">InnoDb:</span></p><span style="color: black;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">支持ACID的事务,支持事务的四种隔离级别;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">支持行级锁及外键约束:<span style="color: black;">因此呢</span><span style="color: black;">能够</span>支持写并发;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">不存储总行数;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">一个InnoDb引擎存储在一个文件空间(共享表空间,表<span style="color: black;">体积</span>不受操作系统<span style="color: black;">掌控</span>,一个表可能分布在多个文件里)</p><span style="color: black;">亦</span>有可能为多个(设置为独立表空,表<span style="color: black;">体积</span>受操作系统文件<span style="color: black;">体积</span>限制,<span style="color: black;">通常</span>为<span style="color: black;">2</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">G),受操作系统文件<span style="color: black;">体积</span>的限制;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">主键索引采用聚集索引(索引的数据域存储数据文件本身),辅索引的数据域存储主键的值;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">因此呢</span>从辅索引<span style="color: black;">查询</span>数据,<span style="color: black;">必须</span>先<span style="color: black;">经过</span>辅索引找到主键值,再<span style="color: black;">拜访</span>辅索引;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">最好<span style="color: black;">运用</span>自增主键,防止<span style="color: black;">插进</span>数据时,为维持B+树结构,文件的大<span style="color: black;">调节</span>。</p>
</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">4.Mysql中InnoDB支持的四种事务隔离级别名<span style="color: black;">叫作</span>,以及逐级之间的区别?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">SQL标准定义的四个隔离级别为:</span></p><span style="color: black;">read uncommited :读到未提交数据</span><span style="color: black;">read committed:脏读,不可重复读</span><span style="color: black;">repeatable read:可重读</span><span style="color: black;">serializable :串行事物</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">5.CHAR和VARCHAR的区别?</span></span></h2><span style="color: black;">CHAR和VARCHAR类型在存储和检索方面有所<span style="color: black;">区别</span></span><span style="color: black;">CHAR列长度固定为创建表时声明的长度,长度值范围是1到255</span><span style="color: black;">当CHAR值被存储时,它们被用空格填充到特定长度,检索CHAR值时需删除尾随空格。</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">6.主键和候选键有什么区别?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">表格的每一行都由主键<span style="color: black;">独一</span>标识,一个表<span style="color: black;">仅有</span>一个主键。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">主键<span style="color: black;">亦</span>是候选键。<span style="color: black;">根据</span>惯例,候选键<span style="color: black;">能够</span>被指定为主键,并且<span style="color: black;">能够</span>用于任何外键引用。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">7.myisamchk是用来做什么的?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">它用来压缩MyISAM表,这减少了磁盘或内存<span style="color: black;">运用</span>。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">8.MyISAM Static和MyISAM Dynamic有什么区别?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在MyISAM Static上的所有字段有固定宽度。动态MyISAM表将<span style="color: black;">拥有</span>像TEXT,BLOB等字段,以适应<span style="color: black;">区别</span>长度的数据类型。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">MyISAM Static在受损<span style="color: black;">状况</span>下<span style="color: black;">更易</span>恢复。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">9.<span style="color: black;">倘若</span>一个表有一列定义为TIMESTAMP,将<span style="color: black;">出现</span>什么?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">每当行被更改时,时间戳字段将获取当前时间戳。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">10.列设置为AUTO INCREMENT时,<span style="color: black;">倘若</span>在表中达到最大值,会<span style="color: black;">出现</span>什么<span style="color: black;">状况</span>?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">它会停止递增,任何进一步的<span style="color: black;">插进</span>都将产生错误,<span style="color: black;">由于</span>密钥已被<span style="color: black;">运用</span>。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">11.<span style="color: black;">怎么样</span><span style="color: black;">才可</span>找出最后一次<span style="color: black;">插进</span>时分配了哪个自动增量?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">LAST_INSERT_ID将返回由Auto_increment分配的最后一个值,并且不<span style="color: black;">必须</span>指定表名<span style="color: black;">叫作</span>。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">12.<span style="color: black;">怎样</span>看到为表格定义的所有索引?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">索引是<span style="color: black;">经过</span>以下方式为表格定义的:</span></p><span style="color: black;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">SHOW INDEX FROM ;
</p>
</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">13.LIKE声明中的%和_是什么意思?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">%对应于0个或<span style="color: black;">更加多</span>字符,_只是LIKE语句中的一个字符。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">14.<span style="color: black;">怎样</span>在Unix和Mysql时间戳之间进行转换?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">UNIX_TIMESTAMP</span><span style="color: black;">是从</span><span style="color: black;">Mysql</span><span style="color: black;">时间戳转换为Unix时间戳的命令 FROM_UNIXTIME是从Unix时间戳转换为Mysql时间戳的命令</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">15.列对比运算符是什么?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在SELECT语句的列比较中<span style="color: black;">运用</span></span><span style="color: black;">=,<>,<=,<,> =,>,<<,>>,<=>,AND,OR</span><span style="color: black;">或</span><span style="color: black;">LIKE</span><span style="color: black;">运算符。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">16.BLOB和TEXT有什么区别?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">BLOB是一个二进制对象,<span style="color: black;">能够</span>容纳可变数量的数据。TEXT是一个不区分<span style="color: black;">体积</span>写的BLOB。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">BLOB和TEXT类型之间的<span style="color: black;">独一</span>区别在于对BLOB值进行排序和比较时区分<span style="color: black;">体积</span>写,对TEXT值不区分<span style="color: black;">体积</span>写。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">17.mysql_fetch_array和mysql_fetch_object的区别是什么?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">mysql_fetch_array() – 将结果行<span style="color: black;">做为</span><span style="color: black;">相关</span>数组或来自数据库的常规数组返回。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">mysql_fetch_object – 从数据库返回结果行<span style="color: black;">做为</span>对象。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">18.MyISAM表类型将在哪里存储,并且还<span style="color: black;">供给</span>其存储格式?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">每一个</span>MyISAM表格以三种格式存储在磁盘上:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">“.frm”文件 存储表定义</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">数据文件<span style="color: black;">拥有</span>“.MYD”(MYData)扩展名</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">索引文件<span style="color: black;">拥有</span>“.MYI”(MYIndex)扩展名</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">19.Mysql<span style="color: black;">怎样</span>优化DISTINCT?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">DISTINCT在所有列上转换为GROUP BY,并与ORDER BY子句结合<span style="color: black;">运用</span>。</span></p><span style="color: black;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;</p>
</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">20.<span style="color: black;">能够</span><span style="color: black;">运用</span>多少列创建索引?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">任何标准表最多<span style="color: black;">能够</span>创建16个索引列。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">21.NOW()和CURRENT_DATE()有什么区别?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">NOW()</span><span style="color: black;">命令用于<span style="color: black;">表示</span>当前年份,月份,日期,小时,分钟和秒。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">CURRENT_DATE()</span><span style="color: black;">仅<span style="color: black;">表示</span>当前年份,月份和日期。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">22.什么是非标准字符串类型?</span></span></h2><span style="color: black;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> TINYTEXT</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> TEXT</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> MEDIUMTEXT</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> LONGTEXT</p>
</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">23.什么是通用SQL函数?</span></span></h2><span style="color: black;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> CONCAT(A, B) – 连接两个字符串值以创建单个字符串输出。<span style="color: black;">一般</span>用于将两个或多个字段合并为一个字段。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">FORMAT(X, D)- 格式化数字X到D有效数字。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> CURRDATE(), CURRTIME()- 返回当前日期或时间。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> NOW() – 将当前日期和时间<span style="color: black;">做为</span>一个值返回。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> MONTH(),DAY(),YEAR(),WEEK(),WEEKDAY() – 从日期值中提取给定数据。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">HOUR(),MINUTE(),SECOND() – 从时间值中提取给定数据。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> DATEDIFF(A,B) – 确定两个日期之间的差异,<span style="color: black;">一般</span>用于计算年龄</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> SUBTIMES(A,B) – 确定两次之间的差异。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> FROMDAYS(INT) – 将整数天数转换为日期值。</p>
</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">24.MYSQL支持事务吗?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在缺省模式下,</span><span style="color: black;">MYSQL</span><span style="color: black;">是</span><span style="color: black;">autocommit</span><span style="color: black;">模式的,所有的数据库更新操作都会即时提交,<span style="color: black;">因此</span>在缺省<span style="color: black;">状况</span>下,mysql是不支持事务的。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">然则</span><span style="color: black;">倘若</span>你的MYSQL表类型是<span style="color: black;">运用</span>InnoDB Tables 或 BDB tables的话,你的MYSQL就<span style="color: black;">能够</span><span style="color: black;">运用</span>事务处理,<span style="color: black;">运用</span>SET AUTOCOMMIT=0就<span style="color: black;">能够</span>使MYSQL<span style="color: black;">准许</span>在非autocommit模式,在非autocommit模式下,你<span style="color: black;">必要</span><span style="color: black;">运用</span>COMMIT来提交你的更改,<span style="color: black;">或</span>用ROLLBACK来回滚你的更改。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">25.mysql里记录货币用什么字段类型好</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">NUMERIC和DECIMAL类型被Mysql实现为<span style="color: black;">一样</span>的类型,这在SQL92标准<span style="color: black;">准许</span>。<span style="color: black;">她们</span>被用于<span style="color: black;">保留</span>值,该值的准确精度是极其重要的值,例如与金钱<span style="color: black;">相关</span>的数据。当声明一个类是这些类型之一时,精度和规模的能被(并且<span style="color: black;">一般</span>是)指定。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">例如:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">salary DECIMAL(9,2)</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在这个例子中,9(precision)<span style="color: black;">表率</span>将被用于存储值的总的小数位数,而2(scale)<span style="color: black;">表率</span>将被用于存储小数点后的位数。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">因此呢</span>,在这种<span style="color: black;">状况</span>下,能被存储在salary列中的值的范围是从-9999999.99到9999999.99。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">26.mysql<span style="color: black;">相关</span>权限的表都有哪几个?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Mysql服务器<span style="color: black;">经过</span>权限表来<span style="color: black;">掌控</span>用户对数据库的<span style="color: black;">拜访</span>,权限表存放在mysql数据库里,由mysql_install_db脚本初始化。这些权限表分别user,db,table_priv,columns_priv和host。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">27.列的字符串类型<span style="color: black;">能够</span>是什么?</span></span></h2><span style="color: black;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> SET</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> BLOB</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> ENUM</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> CHAR</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> TEXT</p>
</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">28.MySQL数据库运维</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">MySQL数据库作发布系统的存储,一天五万条以上的增量,预计运维三年,怎么优化?</span></p><span style="color: black;">设计良好的数据库结构,<span style="color: black;">准许</span>部分数据冗余,<span style="color: black;">尽可能</span>避免join<span style="color: black;">查找</span>,提<span style="color: black;">有效</span>率。</span><span style="color: black;"><span style="color: black;">选取</span>合适的表字段数据类型和存储引擎,适当的添加索引。</span><span style="color: black;">mysql库主从读写分离。</span><span style="color: black;">找规律分表,减少单表中的数据量<span style="color: black;">加强</span><span style="color: black;">查找</span>速度。</span><span style="color: black;">添加缓存机制,<span style="color: black;">例如</span>memcached,redis等。</span><span style="color: black;">不经常改动的页面,生成静态页面。</span><span style="color: black;">书写<span style="color: black;">有效</span>率的SQL。<span style="color: black;">例如</span> </span><span style="color: black;">SELECT * FROM TABEL</span><span style="color: black;"> 改为 </span><span style="color: black;">SELECT field_1, field_2, field_3 FROM TABLE</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">29.锁的优化策略</span></span></h2><span style="color: black;">读写分离</span><span style="color: black;">分段加锁</span><span style="color: black;">减少锁持有的时间</span><span style="color: black;">多个线程<span style="color: black;">尽可能</span>以相同的<span style="color: black;">次序</span>去获取资源</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">不可</span>将锁的粒度过于细化,<span style="color: black;">否则</span>可能会<span style="color: black;">显现</span>线程的加锁和释放次数<span style="color: black;">太多</span>,反而效率不如一次加一把大锁。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">30.索引的底层实现原理和优化</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">B+树,经过优化的B+树</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">重点</span>是在所有的叶子结点中<span style="color: black;">增多</span>了指向下一个叶子节点的指针,<span style="color: black;">因此呢</span>InnoDB建议为大部分表<span style="color: black;">运用</span>默认自增的主键<span style="color: black;">做为</span>主索引。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">31.什么<span style="color: black;">状况</span>下设置了索引但<span style="color: black;">没法</span><span style="color: black;">运用</span></span></span></h2><span style="color: black;">以“%”开头的LIKE语句,模糊匹配</span><span style="color: black;">OR语句前后<span style="color: black;">无</span><span style="color: black;">同期</span><span style="color: black;">运用</span>索引</span><span style="color: black;">数据类型<span style="color: black;">显现</span>隐式转化(如varchar不加单引号的话可能会自动转换为int型)</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">32实践中<span style="color: black;">怎样</span>优化MySQL</span></span></h2><span style="color: black;">SQL语句及索引的优化</span><span style="color: black;">数据库表结构的优化</span><span style="color: black;">系统配置的优化</span><span style="color: black;">硬件的优化</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">仔细</span><span style="color: black;">能够</span>查看 阿里P8架构师谈:MySQL慢<span style="color: black;">查找</span>优化、索引优化、以及表等优化总结</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">33.优化数据库的<span style="color: black;">办法</span></span></span></h2><span style="color: black;"><span style="color: black;">选择</span>最适用的字段属性,尽可能减少定义字段宽度,<span style="color: black;">尽可能</span>把字段设置NOTNULL,例如’省份’、’性别’最好适用ENUM</span><span style="color: black;"><span style="color: black;">运用</span>连接(JOIN)来代替子<span style="color: black;">查找</span></span><span style="color: black;">适用联合(UNION)来代替手动创建的临时表</span><span style="color: black;">事务处理</span><span style="color: black;">锁定表、优化事务处理</span><span style="color: black;">适用外键,优化锁定表</span><span style="color: black;"><span style="color: black;">创立</span>索引</span><span style="color: black;">优化<span style="color: black;">查找</span>语句</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">34.简单描述mysql中,索引,主键,<span style="color: black;">独一</span>索引,联合索引的区别,对数据库的性能有什么影响(从读写两方面)</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">索引是一种特殊的文件(InnoDB数据表上的索引是表空间的一个<span style="color: black;">构成</span>部分),它们<span style="color: black;">包括</span>着对数据表里所有记录的引用指针。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">普通索引(由关键字KEY或INDEX定义的索引)的<span style="color: black;">独一</span>任务是加快对数据的<span style="color: black;">拜访</span>速度。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">普通索引<span style="color: black;">准许</span>被索引的数据列<span style="color: black;">包括</span>重复的值。<span style="color: black;">倘若</span>能确定某个数据列将只<span style="color: black;">包括</span>彼此各不相同的值,在为这个数据列创建索引的时候就应该用关键字UNIQUE把它定义为一个<span style="color: black;">独一</span>索引。<span style="color: black;">亦</span><span style="color: black;">便是</span>说,<span style="color: black;">独一</span>索引<span style="color: black;">能够</span><span style="color: black;">保准</span>数据记录的<span style="color: black;">独一</span>性。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">主键,是一种特殊的<span style="color: black;">独一</span>索引,在一张表中只能定义一个主键索引,主键用于<span style="color: black;">独一</span>标识一条记录,<span style="color: black;">运用</span>关键字 PRIMARY KEY 来创建。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">索引<span style="color: black;">能够</span>覆盖多个数据列,如像INDEX(columnA, columnB)索引,这<span style="color: black;">便是</span>联合索引。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">索引<span style="color: black;">能够</span><span style="color: black;">极重</span>的<span style="color: black;">加强</span>数据的<span style="color: black;">查找</span>速度,<span style="color: black;">然则</span>会降低<span style="color: black;">插进</span>、删除、更新表的速度,<span style="color: black;">由于</span>在执行这些写操作时,还要操作索引文件。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">35.数据库中的事务是什么?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">事务(transaction)是<span style="color: black;">做为</span>一个单元的一组有序的数据库操作。<span style="color: black;">倘若</span>组中的所有操作都成功,则认为事务成功,即使<span style="color: black;">仅有</span>一个操作失败,事务<span style="color: black;">亦</span>不成功。<span style="color: black;">倘若</span>所有操作完成,事务则提交,其修改将<span style="color: black;">功效</span>于所有其他数据库进程。<span style="color: black;">倘若</span>一个操作失败,则事务将回滚,该事务所有操作的影响都将取消。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">事务特性:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">(1)原子性:即不可分割性,事务要么<span style="color: black;">所有</span>被执行,要么就<span style="color: black;">所有</span>不被执行。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">(2)一致性或可串性。事务的执行使得数据库从一种正确状态转换成另一种正确状态</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">(3)隔离性。在事务正确提交之前,不<span style="color: black;">准许</span>把该事务对数据的任何改变<span style="color: black;">供给</span>给任何其他事务,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">(4) 持久性。事务正确提交后,其结果将永久<span style="color: black;">保留</span>在数据库中,即使在事务提交后有了其他故障,事务的处理结果<span style="color: black;">亦</span>会得到<span style="color: black;">保留</span>。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">通俗理解事务</strong>:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">事务<span style="color: black;">便是</span>被绑定在<span style="color: black;">一块</span><span style="color: black;">做为</span>一个<span style="color: black;">规律</span>工作单元的SQL语句分组,<span style="color: black;">倘若</span>任何一个语句操作失败<span style="color: black;">那样</span><span style="color: black;">全部</span>操作就被失败,以后操作就会回滚到操作前状态,<span style="color: black;">或</span>是上有个节点。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">为了<span style="color: black;">保证</span>要么执行,要么不执行,就<span style="color: black;">能够</span><span style="color: black;">运用</span>事务。要将有组语句<span style="color: black;">做为</span>事务<span style="color: black;">思虑</span>,就<span style="color: black;">必须</span><span style="color: black;">经过</span>ACID测试,即原子性,一致性,隔离性和持久性。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">36.SQL注入漏洞产生的<span style="color: black;">原由</span>?<span style="color: black;">怎样</span>防止?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">SQL注入产生的<span style="color: black;">原由</span>:程序<span style="color: black;">研发</span>过程中不<span style="color: black;">重视</span>规范书写sql语句和对特殊字符进行过滤,<span style="color: black;">引起</span>客户端<span style="color: black;">能够</span><span style="color: black;">经过</span>全局变量POST和GET提交<span style="color: black;">有些</span>sql语句正常执行。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">防止SQL注入的方式:</span></p><span style="color: black;">开启配置文件中的magic_quotes_gpc 和 magic_quotes_runtime设置</span><span style="color: black;">执行sql语句时<span style="color: black;">运用</span>addslashes进行sql语句转换</span><span style="color: black;">Sql语句书写<span style="color: black;">尽可能</span>不要省略双引号和单引号。</span><span style="color: black;">过滤掉sql语句中的<span style="color: black;">有些</span>关键词:</span><span style="color: black;">update、insert、delete、select、 *</span><span style="color: black;"> 。</span><span style="color: black;"><span style="color: black;">加强</span>数据库表和字段的命名技巧,对<span style="color: black;">有些</span>重要的字段<span style="color: black;">按照</span>程序的特点命名,取<span style="color: black;">很难</span>被猜到的。</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">37.为表中得字段<span style="color: black;">选取</span>合适得数据类型</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">字段类型优先级: 整形>date,time>enum,char>varchar>blob,text 优先<span style="color: black;">思虑</span>数字类型,其次是日期<span style="color: black;">或</span>二进制类型,最后是字符串类型,同级别得数据类型,应该优先<span style="color: black;">选取</span>占用空间小的数据类型</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">38.存储时期</span></span></h2><span style="color: black;">Datatime:以 YYYY-MM-DD HH:MM:SS 格式存储时期时间,精确到秒,占用8个字节得存储空间;</span><span style="color: black;">datatime类型与时区无关 Timestamp:以时间戳格式存储,占用4个字节,范围小1970-1-1到2038-1-19,<span style="color: black;">表示</span>依赖于所指定得时区,默认在<span style="color: black;">第1</span>个列行的数据修改时<span style="color: black;">能够</span>自动得修改timestamp列的值</span><span style="color: black;">Date:(生日)占用得字节数比<span style="color: black;">运用</span>字符串.datatime.int储存要少,<span style="color: black;">运用</span>date只<span style="color: black;">必须</span>3个字节,存储日期月份,还<span style="color: black;">能够</span>利用日期时间函数进行日<span style="color: black;">时期</span>得计算</span><span style="color: black;">Time:存储时间部分得数据 <span style="color: black;">重视</span>:不要<span style="color: black;">运用</span>字符串类型来存储日期时间数据(<span style="color: black;">一般</span>比字符串占用得储存空间小,在进行<span style="color: black;">查询</span>过滤<span style="color: black;">能够</span>利用日期得函数) <span style="color: black;">运用</span>int存储日期时间不如<span style="color: black;">运用</span>timestamp类型</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">39.索引<span style="color: black;">关联</span>(关系型数据库MySQL):</span></span></h2>
<h3 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">索引的目的是什么?</span></span></h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">快速<span style="color: black;">拜访</span>数据表中的特定信息,<span style="color: black;">加强</span>检索速度
创建<span style="color: black;">独一</span>性索引,<span style="color: black;">保准</span>数据库表中每一行数据的<span style="color: black;">独一</span>性。加速表和表之间的连接
<span style="color: black;">运用</span>分组和排序子句进行数据检索时,<span style="color: black;">能够</span><span style="color: black;">明显</span>减少<span style="color: black;">查找</span>中分组和排序的时间</span></p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">索引对数据库系统的<span style="color: black;">消极</span>影响是什么?</span></span></h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">消极</span>影响:创建索引和<span style="color: black;">守护</span>索引<span style="color: black;">必须</span>耗费时间,这个时间随着数据量的<span style="color: black;">增多</span>而<span style="color: black;">增多</span>;索引<span style="color: black;">必须</span>占用<span style="color: black;">理学</span>空间,<span style="color: black;">不但</span>是表<span style="color: black;">必须</span>占用数据空间,<span style="color: black;">每一个</span>索引<span style="color: black;">亦</span><span style="color: black;">必须</span>占用<span style="color: black;">理学</span>空间;当对表进行增、删、改、的时候索引<span style="color: black;">亦</span>要动态<span style="color: black;">守护</span>,<span style="color: black;">这般</span>就降低了数据的<span style="color: black;">守护</span>速度。</span></p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">为数据表<span style="color: black;">创立</span>索引的原则有<span style="color: black;">那些</span>?</span></span></h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在最频繁<span style="color: black;">运用</span>的、用以缩小<span style="color: black;">查找</span>范围的字段上<span style="color: black;">创立</span>索引。在频繁<span style="color: black;">运用</span>的、<span style="color: black;">必须</span>排序的字段上<span style="color: black;">创立</span>索引</span></p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">什么<span style="color: black;">状况</span>下不宜<span style="color: black;">创立</span>索引?</span></span></h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">针对</span><span style="color: black;">查找</span>中很少<span style="color: black;">触及</span>的列<span style="color: black;">或</span>重复值比较多的列,不宜<span style="color: black;">创立</span>索引。<span style="color: black;">针对</span><span style="color: black;">有些</span>特殊的数据类型,不宜<span style="color: black;">创立</span>索引,<span style="color: black;">例如</span>文本字段(text)等</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">40.解释MySQL外连接、内连接与自连接的区别</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">先说什么是交叉连接: <strong style="color: blue;">交叉连接又叫笛卡尔积</strong>,它<span style="color: black;">指的是</span>不<span style="color: black;">运用</span>任何<span style="color: black;">要求</span>,直接将一个表的所有记录和另一个表中的所有记录一一匹配。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">内连接 则是<span style="color: black;">仅有</span><span style="color: black;">要求</span>的交叉连接,<span style="color: black;">按照</span>某个<span style="color: black;">要求</span>筛选出符合<span style="color: black;">要求</span>的记录,不符合<span style="color: black;">要求</span>的记录不会出<span style="color: black;">此刻</span>结果集中,即内连接只连接匹配的行。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">外连接 其结果集中不仅<span style="color: black;">包括</span>符合连接<span style="color: black;">要求</span>的行,<span style="color: black;">况且</span>还会<span style="color: black;">包含</span>左表、右表或两个表中的所有数据行,这三种<span style="color: black;">状况</span>依次<span style="color: black;">叫作</span>之为左外连接,右外连接,和全外连接。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">左外连接 <span style="color: black;">亦</span><span style="color: black;">叫作</span>左连接,左表为主表,左表中的所有记录都会出<span style="color: black;">此刻</span>结果集中,<span style="color: black;">针对</span><span style="color: black;">哪些</span>在右表中并<span style="color: black;">无</span>匹配的记录,仍然要<span style="color: black;">表示</span>,右边对应的<span style="color: black;">哪些</span>字段值以NULL来填充。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">右外连接 <span style="color: black;">亦</span><span style="color: black;">叫作</span>右连接,右表为主表,右表中的所有记录都会出<span style="color: black;">此刻</span>结果集中。左连接和右连接<span style="color: black;">能够</span>互换,MySQL<span style="color: black;">日前</span>还不支持全外连接。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">41.Myql中的事务回滚机制概述</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">事务是用户定义的一个数据库操作序列,这些操作要么全做要么全不做,是一个不可分割的工作单位,事务回滚<span style="color: black;">指的是</span>将该事务<span style="color: black;">已然</span>完成的对数据库的更新操作撤销。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">要<span style="color: black;">同期</span>修改数据库中两个<span style="color: black;">区别</span>表时,<span style="color: black;">倘若</span>它们不是一个事务的话,当<span style="color: black;">第1</span>个表修改完,可能第二个表修改过程中<span style="color: black;">显现</span>了<span style="color: black;">反常</span>而没能修改,此时就<span style="color: black;">仅有</span>第二个表依旧是未修改之前的状态,而<span style="color: black;">第1</span>个表<span style="color: black;">已然</span>被修改完毕。而当你把它们设定为一个事务的时候,当<span style="color: black;">第1</span>个表修改完,第二表修改<span style="color: black;">显现</span><span style="color: black;">反常</span>而没能修改,<span style="color: black;">第1</span>个表和第二个表都要回到未修改的状态,这<span style="color: black;">便是</span><span style="color: black;">所说</span>的事务回滚</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">42.SQL语言<span style="color: black;">包含</span>哪几部分?每部分都有<span style="color: black;">那些</span>操作关键字?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">SQL语言<span style="color: black;">包含</span>数据定义(DDL)、数据<span style="color: black;">操作</span>(DML),数据<span style="color: black;">掌控</span>(DCL)和数据<span style="color: black;">查找</span>(DQL)四个部分。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">数据定义:Create Table,Alter Table,Drop Table, Craete/Drop Index等</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">数据<span style="color: black;">操作</span>:Select ,insert,update,delete,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">数据<span style="color: black;">掌控</span>:grant,revoke</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">数据<span style="color: black;">查找</span>:select</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">43.完整性约束<span style="color: black;">包含</span><span style="color: black;">那些</span>?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">数据完整性(Data Integrity)<span style="color: black;">指的是</span>数据的精确(Accuracy)和<span style="color: black;">靠谱</span>性(Reliability)。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">分为以下四类:</span></p><span style="color: black;">实体完整性:规定表的每一行在表中是惟一的实体。</span><span style="color: black;">域完整性:<span style="color: black;">指的是</span>表中的列<span style="color: black;">必要</span>满足某种特定的数据类型约束,其中约束又<span style="color: black;">包含</span>取值范围、精度等规定。</span><span style="color: black;">参照完整性:<span style="color: black;">指的是</span>两个表的主关键字和外关键字的数据应一致,<span style="color: black;">保准</span>了表之间的数据的一致性,防止了数据丢失或无<span style="color: black;">道理</span>的数据在数据库中扩散。</span><span style="color: black;">用户定义的完整性:<span style="color: black;">区别</span>的关系数据库系统<span style="color: black;">按照</span>其应用环境的<span style="color: black;">区别</span>,<span style="color: black;">常常</span>还<span style="color: black;">必须</span><span style="color: black;">有些</span>特殊的约束<span style="color: black;">要求</span>。用户定义的完整性即是针对某个特定关系数据库的约束<span style="color: black;">要求</span>,它反映某一<span style="color: black;">详细</span>应用<span style="color: black;">必要</span>满足的语义<span style="color: black;">需求</span>。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">与表<span style="color: black;">相关</span>的约束:<span style="color: black;">包含</span>列约束(NOT NULL(非空约束))和表约束(PRIMARY KEY、foreign key、check、UNIQUE) 。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">44.MySQL的锁?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">数据库是一个多用户<span style="color: black;">运用</span>的共享资源。当多个用户并发地存取数据时,在数据库中就会产生多个事务<span style="color: black;">同期</span>存取同一数据的<span style="color: black;">状况</span>。若对并发操作不加<span style="color: black;">掌控</span>就可能会读取和存储不正确的数据,破坏数据库的一致性。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">加锁是实现数据库并发<span style="color: black;">掌控</span>的一个非常重要的技术。当事务在对某个数据对象进行操作前,先向系统发出请求,对其加锁。加锁后事务就对该数据对象有了<span style="color: black;">必定</span>的<span style="color: black;">掌控</span>,在该事务释放锁之前,其他的事务<span style="color: black;">不可</span>对此数据对象进行更新操作。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">基本锁类型:<strong style="color: blue;">锁<span style="color: black;">包含</span>行级锁和表级锁</strong></span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">45.什么叫视图?游标是什么?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">视图是一种虚拟的表,<span style="color: black;">拥有</span>和<span style="color: black;">理学</span>表相同的功能</strong>。<span style="color: black;">能够</span>对视图进行增,改,查,操作,视图<span style="color: black;">一般</span>是有一个表<span style="color: black;">或</span>多个表的行或列的子集。对视图的修改不影响基本表。它使得<span style="color: black;">咱们</span>获取数据<span style="color: black;">更易</span>,相比多表<span style="color: black;">查找</span>。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">游标:是对<span style="color: black;">查找</span>出来的结果集<span style="color: black;">做为</span>一个单元来有效的处理。游标<span style="color: black;">能够</span>定在该单元中的特定行,从结果集的当前行检索一行或多行。<span style="color: black;">能够</span>对结果集当前行做修改。<span style="color: black;">通常</span>不<span style="color: black;">运用</span>游标,<span style="color: black;">然则</span><span style="color: black;">必须</span>逐条处理数据的时候,游标<span style="color: black;">显出</span><span style="color: black;">非常</span>重要。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">46.什么是存储过程?用什么来调用?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">存储过程是一个预编译的SQL语句,优点是<span style="color: black;">准许</span>模块化的设计,<span style="color: black;">便是</span>说只需创建一次,以后在该程序中就<span style="color: black;">能够</span>调用多次。<span style="color: black;">倘若</span>某次操作<span style="color: black;">必须</span>执行多次SQL,<span style="color: black;">运用</span>存储过程比单纯SQL语句执行要快。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">能够</span>用一个<strong style="color: blue;">命令对象</strong>来调用存储过程。</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">47.<span style="color: black;">怎样</span>通俗地理解三个范式?</span></span></h2>
<h3 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">概念</span></span></h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">第1</span>范式:1NF是对属性的原子性约束,<span style="color: black;">需求</span>属性<span style="color: black;">拥有</span>原子性,不可再分解;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第二范式:2NF是对记录的惟一性约束,<span style="color: black;">需求</span>记录有惟一标识,即实体的惟一性;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第三范式:3NF是对字段冗余性的约束,即任何字段<span style="color: black;">不可</span>由其他字段派生出来,它<span style="color: black;">需求</span>字段<span style="color: black;">无</span>冗余。。</span></p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">范式化设计优缺点</span></span></h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">优点:<span style="color: black;">能够</span><span style="color: black;">尽可能</span>得减<span style="color: black;">少许</span>据冗余,使得更新快,体积小</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">缺点:<span style="color: black;">针对</span><span style="color: black;">查找</span><span style="color: black;">必须</span>多个表进行<span style="color: black;">相关</span>,减少写得效率<span style="color: black;">增多</span>读得效率,更难进行索引优化</span></p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">反范式化的优缺点</span></span></h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">优点:<span style="color: black;">能够</span>减少表得<span style="color: black;">相关</span>,<span style="color: black;">能够</span>更好得进行索引优化</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">缺点:数据冗余以及数据<span style="color: black;">反常</span>,数据得修改<span style="color: black;">必须</span><span style="color: black;">更加多</span>的成本</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">48.什么是基本表?什么是视图?</span></span></h2><span style="color: black;">基本表是本身独立存在的表,在 SQL 中一个关系就对应一个表。</span><span style="color: black;">视图是从一个或几个基本表导出的表。视图本身不独立存储在数据库中,是一个虚表</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">49.MySQL视图的优点</span></span></h2><span style="color: black;">视图能够简化用户的操作</span><span style="color: black;">视图<span style="color: black;">运用</span>户能以多种<span style="color: black;">方向</span>看待同一数据</span><span style="color: black;">视图为数据库<span style="color: black;">供给</span>了<span style="color: black;">必定</span>程度的<span style="color: black;">规律</span>独立性</span><span style="color: black;">视图能够对机密数据<span style="color: black;">供给</span>安全<span style="color: black;">守护</span>。</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">50. NULL是什么意思</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">NULL这个值<span style="color: black;">暗示</span>UNKNOWN(未知):它不<span style="color: black;">暗示</span>“”(空字符串)。对NULL这个值的任何比较都会生产一个NULL值。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">能够</span><span style="color: black;">运用</span>IS NULL来进行NULL判断</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">51.主键、外键和索引的区别?</span></span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1、从定义上却分</span></p><span style="color: black;">主键:<span style="color: black;">独一</span>标识一条记录,<span style="color: black;">不可</span>有重复的,不<span style="color: black;">准许</span>为空</span><span style="color: black;">外键:表的外键是另一表的主键, 外键<span style="color: black;">能够</span>有重复的, <span style="color: black;">能够</span>是空值</span><span style="color: black;">索引:该字段<span style="color: black;">无</span>重复值,但<span style="color: black;">能够</span>有一个空值</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2、从<span style="color: black;">功效</span>上区分</span></p><span style="color: black;">主键:用来<span style="color: black;">保准</span>数据完整性</span><span style="color: black;">外键:用来和其他表<span style="color: black;">创立</span>联系用的</span><span style="color: black;">索引:是<span style="color: black;">加强</span><span style="color: black;">查找</span>排序的速度</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3、从个数上区分</span></p><span style="color: black;">主键:主键只能有一个</span><span style="color: black;">外键:一个表<span style="color: black;">能够</span>有多个外键</span><span style="color: black;">索引:一个表<span style="color: black;">能够</span>有多个<span style="color: black;">独一</span>索引</span>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><span style="color: black;">52.SQL语句优化<span style="color: black;">办法</span></span></span></h2><span style="color: black;">Where子句中:where表之间的连接<span style="color: black;">必要</span>写在其他Where<span style="color: black;">要求</span>之前,<span style="color: black;">哪些</span><span style="color: black;">能够</span>过滤掉最大数量记录的<span style="color: black;">要求</span><span style="color: black;">必要</span>写在Where子句的末尾.HAVING最后。</span><span style="color: black;">用EXISTS替代IN、用NOT EXISTS替代NOT IN。</span><span style="color: black;">避免在索引列上<span style="color: black;">运用</span>计算</span><span style="color: black;">避免在索引列上<span style="color: black;">运用</span>IS NULL和IS NOT NULL</span><span style="color: black;">对<span style="color: black;">查找</span>进行优化,应<span style="color: black;">尽可能</span>避免全表扫描,<span style="color: black;">首要</span>应<span style="color: black;">思虑</span>在 where 及 order by <span style="color: black;">触及</span>的列上<span style="color: black;">创立</span>索引。</span><span style="color: black;">应<span style="color: black;">尽可能</span>避免在 where 子句中对字段进行 null 值判断,否则将<span style="color: black;">引起</span>引擎放弃<span style="color: black;">运用</span>索引而进行全表扫描</span><span style="color: black;">应<span style="color: black;">尽可能</span>避免在 where 子句中对字段进行表达式操作,这将<span style="color: black;">引起</span>引擎放弃<span style="color: black;">运用</span>索引而进行全表扫描</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">链接:https://github.com/caokegege/Interview</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
谷歌网站排名优化 http://www.fok120.com/ 谷歌外贸网站优化技术。 我深感你的理解与共鸣,愿对话长流。 百度seo优化论坛 http://www.fok120.com/ 可以发布外链的网站 http://www.fok120.com/ 期待楼主的下一次分享!”
页:
[1]