标签 MySQL 下的文章

MySQL 5.0.37 以上开始支持 MySQL Query Profiler, 可以查询到此 SQL 会执行多少时间, 并看出 CPU/Memory 使用量, 执行过程中 System lock, Table lock 花多少时间等等.

启用 MySQL Query Profile

mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)

测试查询语句

mysql> select count(*) from user;
+----------+
| count(*) |
+----------+
|      200 |
+----------+
1 row in set (0.00 sec)

查看 Profiles

mysql> show profiles;
+----------+------------+-----------------------------------------------+
| Query_ID | Duration   | Query                                         |
+----------+------------+-----------------------------------------------+
|        0 | 0.00007300 | set profiling=1                               |
|        1 | 0.00048366 | select count(*) from user |
+----------+------------+-----------------------------------------------+
2 rows in set (0.00 sec)

- 阅读剩余部分 -

我们在平常在开发环境使用 MySQL 的过程中,经常需要命令行登录, 比如:

mysql -h localhost -P 3306 -u root -D steel_server -p
******

mysql>
  • -h 服务地址
  • -P 服务端口
  • -u 服务用户
  • -D 默认数据库
  • -p 输入密码

在开发环境每次都输入这么长的内容, 也挺不方便的,于是看了下, mysql 命令是否支持本地配置的功能, man mysql 中有这部分描述

       ·   Use an option file.  You can set the prompt option in the [mysql] group of any MySQL option file, such as /etc/my.cnf or the .my.cnf file in your home directory. For example:

               [mysql]
               prompt=(\\u@\\h) [\\d]>\\_

- 阅读剩余部分 -