mysql> explain select count(*) from stu where name like "a%"\G
*************************** 1. row *************************** id: 1 select_type: SIMPLE
table: stu
type: range
possible_keys: name,ind_stu_name
key: name
key_len: 50 ref: NULL rows: 8 Extra: Using where; Using index 1 row in set (0.00 sec)
id: 1select_type: SIMPLE 表示select的类型,常见的取值有SIMPLE()简单表,即不使用表连接或者子查询)、PRIMARY(主查询,即外层的查询)、UNION(UNION中的第二个或者后面的查询语句)、SUBQUERY(子查询中的第一个SESECT)等table: stu 输出结果集的表type: range 表示表的连接类型,性能有好到差:system(表仅一行)、const(只一行匹配)、eq_ref(对于前面的每一行使用主键和唯一)、ref(同eq_ref,但没有使用主键和唯一)、ref_or_null(同前面对null查询)、index_merge(索引合并优化)、unique_subquery(主键子查询)、index_subquery(非主键子查询)、range(表单中的范围查询)、index(都通过查询索引来得到数据)、all(通过全表扫描得到的数据)possible_keys: name,ind_stu_name 表查询时可能使用的索引。key: name 表示实际使用的索引。key_len: 50 索引字段的长度ref: NULLrows: 8 扫描行的数量Extra: Using where; Using index 执行情况的说明和描述
mysql> explain select id,sum(moneys) from sales2 group by id order by null\G
*************************** 1. row *************************** id: 1 select_type: SIMPLE
table: sales2
type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 1000 Extra: Using temporary 1 row in set (0.00 sec)
mysql> explain select * from sales2 left join company2 on sales2.company_id = company2.id where sales2.company_id is null\G
*************************** 1. row ***************************id: 1 select_type: SIMPLE
table: sales2
type: ALL possible_keys: ind_sales2_companyid_moneys
key: ind_sales2_companyid_moneys
key_len: 5 ref: count rows: 1 Extra: Using where 1 row in set (0.00 sec)
1.log-bin=mysql-bin
查看bin-log日志:
mysql> show binary logs; 查看最后一个bin-log日志:
mysql> show master status;
慢查询日志
开户和设置慢查询时间:
vi /etc/my.cnflog_slow_queries=slow.loglong_query_time=5 慢查询次数:
mysql> show global status like "%quer%"
socket问题
mysql socket无法登录
1. 有时登录mysql时提示不能用socket登录,此时可以换成tcp方式去登录,但是可以测试时可以这样用,但是必须要在php去用之前把这个事情解决了.
[root@localhost mysql]# mysql -uroot -pwei --protocol tcp -hlocalhost
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 34Server version: 5.0.77-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
root密码丢失破解1.service mysqld stop2. mysqld_safe --skip-grant-tables --user=mysql &
//跳过授权表mysql.user和mysql.db这些表3. mysql -uroot4. set password=password("wei");
//用这一条语句结果报错,就是因为加了--skip-grant-tables4. mysql>update user set password=password("wei") where user='root' and host='localhost';5. mysql> set password for root@localhost=password("wei");6. mysql> set password=password("wei");