• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >Mysql > mysql常用知识整理

mysql常用知识整理

作者: 字体:[增加 减小] 来源:互联网 时间:2017-12-17

通过本文主要向大家介绍了mysql等相关知识,希望本文的分享对您有所帮助

mysql官网下载地址
https://www.mysql.com/downloads/

Download MySQL Community Server
自己选择操作系统。ubuntu的安装如下:

sudo apt-get install mysql-server mysql-client

sudo service mysql restart

让apache支持mysql(可选)

sudo apt-get install libapache2-mod-auth-mysql

让php支持mysql(可选)

sudo apt-get install php5-mysql

登陆可以是windows或者linux

mysql -u root -p

使用mysql(选择的数据库名)数据库

use mysql

无法远程访问的办法
http://blog.csdn.net/mydeman/article/details/3847695

使用SHOW PROFILE

show profile 命令实在MySQL 5.1以后的版本引入的,来源于开源社区中的Jeremy Cole的贡献。默认是禁用的。会话(连接)级别开启show profile命令;

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

然后,在服务器上执行的所有有语句,都会测量其耗费的时间和其他一些查询执行状态变更相关的数据。
先看个测试;

mysql> select * from proc;

结果有点长;下面查看show profiles;

mysql> show profiles;
+----------+------------+--------------------+
| Query_ID | Duration   | Query              |
+----------+------------+--------------------+
|        1 | 0.00109700 | select * from proc |
+----------+------------+--------------------+
1 row in set, 1 warning (0.00 sec)

上面显示了测量的语句执行时间;下面看看具体耗时;

mysql> show profile for query 1;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000040 |
| checking permissions | 0.000004 |
| Opening tables       | 0.000168 |
| init                 | 0.000015 |
| System lock          | 0.000004 |
| optimizing           | 0.000002 |
| statistics           | 0.000007 |
| preparing            | 0.000006 |
| executing            | 0.000001 |
| Sending data         | 0.000815 |
| end                  | 0.000003 |
| query end            | 0.000003 |
| closing tables       | 0.000005 |
| freeing items        | 0.000018 |
| cleaning up          | 0.000008 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)

上面就是查到的结果;但是无法是用order by排序,所以不容易查看哪个步骤花费时间最长;
可以使用下面方式查————通过查看INFORMATION_SCHEMA中对应的表;

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

mysql> select state,sum(duration) as total_r,
    ->     round(
    ->        100 * sum(duration) /
    ->            (select sum(duration) from information_schema.profiling
    ->              where query_id = @query_id
    ->            ),2)  as pct_r,
    ->     count(*) as calls,
    ->     sum(duration) / count(*) as "R/Call"
    -> from information_schema.profiling
    -> where query_id = @query_id
    -> group by state
    -> order by total_r desc;
+----------------------+----------+-------+-------+--------------+
| state                | total_r  | pct_r | calls | R/Call       |
+----------------------+----------+-------+-------+--------------+
| Sending data         | 0.000815 | 74.16 |     1 | 0.0008150000 |
| Opening tables       | 0.000168 | 15.29 |     1 | 0.0001680000 |
| starting             | 0.000040 |  3.64 |     1 | 0.0000400000 |
| freeing items        | 0.000018 |  1.64 |     1 | 0.0000180000 |
| init                 | 0.000015 |  1.36 |     1 | 0.0000150000 |
| cleaning up          | 0.000008 |  0.73 |     1 | 0.0000080000 |
| statistics           | 0.000007 |  0.64 |     1 | 0.0000070000 |
| preparing            | 0.000006 |  0.55 |     1 | 0.0000060000 |
| closing tables       | 0.000005 |  0.45 |     1 | 0.0000050000 |
| System lock          | 0.000004 |  0.36 |     1 | 0.0000040000 |
| checking permissions | 0.000004 |  0.36 |     1 | 0.0000040000 |
| query end            | 0.000003 |  0.27 |     1 | 0.0000030000 |
| end                  | 0.000003 |  0.27 |     1 | 0.0000030000 |
| optimizing           | 0.000002 |  0.18 |     1 | 0.0000020000 |
| executing            | 0.000001 |  0.09 |     1 | 0.0000010000 |
+----------------------+----------+-------+-------+--------------+
15 rows in set, 16 warnings (0.01 sec)

Sending Data(发送数据):这个状态代表的原因非常多,可能是各种不同的服务器活动,包括在关联时搜索匹配的行记录等,这部分很难说能优化节省多少消耗的时间。

SHOW CREATE TABLE

查看mysql中的创建语句(这样可以看到更详细的创建语句,可以把INTEGER、BOOL等别名转换为MySQL的基本数据类型。);

mysql> show create table char_test;
+-----------+------------------------------------------------------------------------------------------------------+
| Table     | Create Table                                                                                         |
+-----------+------------------------------------------------------------------------------------------------------+
| char_test | CREATE TABLE `char_test` (
  `char_col` char(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-----------+------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

参考:高性能MySQL(第3版). Baron Schwartz,Peter Zaitsev,Vadim Tkachenko 著;宁海元,周振兴,彭立勋 等 译

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

相关文章

  • 2018-12-05MySQL中权限管理的详图介绍
  • 2018-12-05主流的NoSQL数据库--MongoDB权限设置的详解
  • 2017-05-11mysql修改密码的三方法和忘记root密码的解决方法
  • 2017-05-11Mysql存储引擎InnoDB和Myisam的六大区别
  • 2018-12-05mysql5.5 master-slave(Replication)主从配置
  • 2017-05-11mysql 设置默认的时间值
  • 2018-12-05sql2000 卸载后重新安装时不能安装的解决办法
  • 2018-12-05java web-mysql 设置事务设置不了(方立勋老师课程)
  • 2018-12-05Mysql常用查询语句
  • 2018-12-05Oracle 自增(auto increment) 或 标识字段的建立方法_Oracle应用

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • 推荐10个监控脚本的实例教程
    • 关于慢查询优化的7篇文章推荐
    • mysql中使用UDF自动同步memcached效率笔记
    • MySQL服务器时间同步问题
    • 如何理解xyz的判断点在凸包内模板
    • 详解MySQL根(Root)密码在Linux(CentOS)下如何重置(图文)
    • JDBC如何连接MySQL数据库?
    • 什么是Mysql中的视图?对Mysql中视图的详解
    • SQL Server 7.0 入门(四)
    • mysql的binlog怎么才能记录除了某表外的操作?

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有