一、设置MySQL自启动
[root@hqw init.d]# chmod +x /etc/init.d/mysql
[root@hqw init.d]# chkconfig --add mysql
[root@hqw init.d]# chkconfig --level 345 mysql on
[root@hqw init.d]# chkconfig --list mysql
mysql 0:off1:off2:on3:on4:on5:on6:off
[root@hqw init.d]# reboot
[root@hqw ~]# netstat -na | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[root@hqw ~]# mysql -h127.0.0.1 -uroot -proot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73-community-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2014-12-12 10:49:57 |
+---------------------+
1 row in set (0.00 sec)
mysql>
二、查看mysql安装目录
[root@hqw ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@hqw ~]# which mysql
/usr/bin/mysql
[root@hqw ~]#
三、查看执行计划
mysql> use ygx;
Database changed
mysql> explain select * from t_page_view_log;
+----+-------------+-----------------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------------+------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | t_page_view_log | ALL | NULL | NULL | NULL | NULL | 1 | |
+----+-------------+-----------------+------+---------------+------+---------+------+------+-------+
1 row in set (0.05 sec)
mysql> explain select * from t_org;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | t_org | ALL | NULL | NULL | NULL | NULL | 3 | |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)
mysql> explain select * from t_org t where t.c_id=1;
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | t | const | PRIMARY | PRIMARY | 8 | const | 1 | |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
1 row in set (0.00 sec)
mysql>
explain select * from t_org t where t.c_id=1;
会产生如下信息:
select_type:表示查询的类型。
table:输出结果集的表
type:表示表的连接类型
possible_keys:表示查询时,可能使用的索引
key:表示实际使用的索引 key_len:索引字段的长度
rows:扫描的行数
Extra:执行情况的描述和说明