select max(id) from test limit #最大值方式 select count(*) from test #常见的 select count(1) from test # 网友说的网上有人对三个查询效率说法不一,有时间去测试一下,大家可以讨论一下
1。请检查出现问题位置的 SQL 语句中是否使用了相同的表名,或是定义了相同的表别名。2。检查 SELECT 语句中要查询的字段名是不是定义重复,或者没有定义。3。把你的sql语句中的换行去掉。一般都是应为这个原因转自:http://wanghui471116899.blog.163.com/blog/static/22837153201071114224177/
这次有点难搞,由于第一次使用nginx和php的php-fpm,mysql也是使用第三方修改过mysql(http://www.percona.com/ 这是增强版的mysql,一个dba推荐给我 ),所以觉得有点难搞,首先就是去检查数据库用户是否远程登录,于是登录mysql,发现的确是不允许远程登录到mysql,然GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%'
InnoDB: auto-extending data file ./ibdata1 is of a different size 640 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages!解决方法:mv /var/li
drop procedure if exists countcomm; delimiter $$ create procedure countcomm (IN param int(10),OUT result varchar(90)) begin declare nums int(11); declare count varchar(20); declare i int(11)
MySQL存储过程参数(in)MySQL存储过程“in”参数:跟C语言的函数参数的值传递类似,MySQL存储过程内部可能会修改此参数,但对in类型参数的修改,对调用者(caller)来说是不可见的(not visible)。MySQL存储过程参数(out)MySQL存储过程“out”参数:从存储过程内部传值给调用者。在存储过程内部,该参数初始值为null,无论调用者是否给存储过程参数设置值MySQ
创建mysql数据表 错误语句:create table blog_article(id int(11) not null UNSIGNED primary key auto_increment,typeid varchar(250),title varchar(250), content text not null,author varchar(250),leavetime int(11))
#创建一个自动生成订单序号的函数20140103001 #作用:可以减少连接数据库的次数,减少数据库的负担,加快程序的的运行 drop function if exists create_sn; delimiter $$ create function test_1.create_sn() returns bigint(15) #编写程序时要注意数据类型 begin declare order_sn bigint(15); declare prev bigint(15); declare prevdatetime bigint(15); declare sn bigint(15); declare nowdate bigint(15); select order_sn from userorder order by userorder_id desc limit 1 into prev; #赋值p
#产生随机字符串,用于测试数据库 drop procedure if exists randstr; delimiter $$ create procedure randstr(num int(11)) #为了容易区分那个函数或者存储过程是那个数据库的,可以在函数名中加上数据库前缀test_randstr; begin declare str char(255) default 'q1we23r4t5y6u7i8o9p0asdfghjklzxcvbnm'; declare nums int(11); declare returnstr char(255); #SQL变量名不能和列名一样 declare i int(11) default 0; #在声明变量时一定要在
#创建存储子程序需要CREATE ROUTINE权限。 #· 提醒或移除存储子程序需要ALTER ROUTINE权限。这个权限自动授予子程序的创建者。 #· 执行子程序需要EXECUTE权限。然而,这个权限自动授予子程序的创建者。同样,子程序默认的SQL SECURITY 特征是DEFINER,它允许用该子程序访问数据库的用户与执行子程序联系到一起 #-------------------------------------------------------------------------------------------------------# #mysql函数即使重启mysqld服务后函数依然会存在,只存在指定的数据库,不会跨数据库 drop database if exists test_1; create database test_1; use test_1; drop table if exists test1; #create table test1 (user_id int(11) auto_increment,user_sn int() not null,
以CentOS-6.4-minimal为基础进行编译(在看这篇文章时建议先把Apache服务器,Nginx编译): 编译时可以参考的文档: 编译文档:http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html 安装文档:http://dev.mysql.com/doc/refman/5.5/en/installing-source-distribution.html 检查gcc编译器: 1 2 3 gcc-v#检查gcc编译器 yum -y installgcc automake autoconf libtool make#安装GCC yum installgcc gcc-c++ #安装C++编译器 下载cmake 1 yum -y install cmake 下载Mysql: 1 2 3 4 5 6 7 8 groupadd mysql user
假设32为当前文章的id 上一遍: mysql完整语句: 1 select * from article where id < 32 and typeid=25 order by id desc limit 0,1 获取到文章的所属类型和小于你当前文章id的所有文章: 1 select * from article where id < 32 andtypeid=25 使用order by id desc 降序 1 select * from article where id < 32 and typeid=25 order by id desc 这时需要获取的文章(即上一遍就会排上第一),加上limit 0,1就可以拿到第一条记录 1 select * from article where id < 32 and typeid=25 order by id d
Mysql 语言分类 Data defintion language 数据定义语言(DDL) Create -在数据库上创建对象 Alter - 修改数据库结构 Drop - 删除对象 Rename - 重命名对象 Data manipulation language 数据库维护语言 (DML) Select - 从数据库中获取数据 Insert - 向一个表中插入数据 Update -更新表格中的数据 Delete - 删除表格中的数据 Data control language 数据控制语言(DCL) Grant - 赋予一个用户对数据库或者表格的读写权限 Revoke - 删除一个用户对数据库或者表格的读写权限 Transaction control (TCL) Commit - 保存数据操作 Savepoint - 为方便rollback标记一个事务点 Rollback - 从最后一次commit中复制提交前的状态
Copyright © 2005-2025 51CTO.COM 版权所有 京ICP证060544号