您好,欢迎光临! 推荐您使用Chrome浏览器访问本站。

记录mysql慢查询

626 views
记录mysql慢查询检测mysql中sql语句的效率的方法 1、通过查询日志 开启MySQL慢查询 Windows中的配置文件一般是my.ini,Linux在etc/my.cnf 在[mysqld]下面加 log-slow-queries = log/mysqlslowquery.log long_query_time =1 slow_query_log_file=/tmp/slow.log 2、mysqldumpslow命令 命令参数说明: -s, 是表示按照何种方式排序,c、t、l、r分别是按照记录次数、时间、查询时间、返回的 记录数来排序,ac、at、al、ar,表示相应的倒叙; -t, 是top n的意思,即为返回前面多少条的数据; -g, 后边可以写一个正则匹配模式,大小写不敏感的; 例子: my......

mysql(php)根据一个坐标求得与数据库中其他坐标的距离

655 views
mysql(php)根据一个坐标求得与数据库中其他坐标的距离 set @x1=114.172668; set @y1=22.314825; set @dist=100; SELECT X(locgeo_baidu),Y(locgeo_baidu),AsText(locgeo_baidu), ROUND( 6378.138*2*ASIN( SQRT( POW(SIN((@y1*PI()/180-Y(locgeo_baidu)*PI()/180)/2),2) +COS(@y1*PI()/180) *COS(Y(locgeo_baidu)*PI()/180) *POW(SIN((@x1*PI()/180-X(locgeo_baidu)*PI()/180)/2),2) ) )*1000 )AS distance from wfgeoloc where locgeo_baidu!='' having distance<@dist ORDER BY distance asc   参考php:http://www.cnblogs.com/wangqishu/p/38......

mysql转移数据报ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

819 views
mysql转移数据报ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)关闭mysql服务: service mysqld stop 转移mysql数据目录 mv /var/lib/mysql/ /data/ 编辑my.cnf vi /etc/my.cnf 修改其中的datadir和socket到新的路径 [mysqld] datadir=/data/mysql socket=/data/mysql/mysql.sock service mysqld start 但是尽管启动服务没有问题,但是通过mysql客户端连接的时候却报错: [root@hostXXX data]# mysql -u root -p Enter password: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) 原因是无法通过socket文件/var/lib/......

MySQL无法远程连接的几种可能

815 views
MySQL无法远程连接的几种可能MySQL无法在远程连接,一般情况下可能是: 1.没有权限 mysql库的user表里设置权限 例子: 第一种方法: grant all privileges on  *.*  to root@’localhost’ identifies by ‘123456’;1 //给localhost主机(本地)的root用户设置123456密码并开所有权限对所有库的所有表(*.*);如果要不限制主机 则把localhost改成 % 第二种方法: 或者更改user表里的数据达到效果 update user set host=”%” where user=”root” and host=”localhost”;1 //你也可以再生成一个专门用于远......

MySQL查询当前数据上一条和下一条的记录

919 views
MySQL查询当前数据上一条和下一条的记录如果ID是主键或者有索引,可以直接查找: 方法一: 查询上一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误): select * from table_a where id = (select id from table_a where id < {$id} [and other_conditions] order by id desc limit 1) [and other_conditions]; 查询下一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误): select * from table_a where id = (select id from table_a where id > {$id} [and other_conditions] order by id a......