Mysql常用命令

Coding Alan 10年前 (2013-11-25) 3447次浏览 0个评论 扫描二维码

查看所有配置:

1118 – Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

连接数据库使用mysql,例如:
mysql -h hostname -u username -p
显示数据库:show databases;
使用数据库:use 数据库名;
显示表格:show tables;
查看表结构: DESC或DESCRIBE 表名;(SQL SERVER使用另一指令sp_help)
显示数据表各字段:show columns from 表名;

新建表格:

create table 表名(
id int(10) NOT NULL auto_increment,
uid varchar(10) NOT NULL default ‘0’,
regdate date NOT NULL,
note text NULL,
PRIMARY KEY (id)
)
drop table
rename table
alter table 表名 drop 字段名;
alter table 表名 add 新字段 after 字段名;

查询语句
select 查询字段 from 表名 where 条件
查询字段:通配符*,字段名(用半角逗号分隔开),别名 select 原字段名 as 别名
表名:数据库.表名或表名两种形式
条件:=等于,<>不等于,>大于,<小于,in包含,not in不包含,like匹配(使用%进行模糊匹配通配符,也可使用_下划线代表一个字符),between…and…范围内,not between…and…范围外;in…, not in…条件运算:and, or
分组:group by 字段名;
排序:order by 字段名 asc(升序,默认方式)/desc(降序);
指针查询:limit 初始值,结束值(只输入一个值时默认从0开始,即从第一条数据开始);
计算:
count(*)统计函数
max(*)最大值函数
min(*)最小值函数
avg(*)平均值函数
sum(*)求和函数(∑)
插入语句
insert into 表名(字段名,… …) values(值, … …);
insert into 表名 values(值, … …);
更新语句
update 表名 set 字段=值 where 条件 limit
删除语句
delete from 表名 where 条件 limit

主从复制

 

通过PHP连接MySQL

首先确认php.ini中的extension=php_mysql.dll组件已开启,mysql_connect(“主机”, “用户名”, “密码”); mysql_select_db(“打开数据库名”,连接标识符); mysql_query(sql语句, 连接标识符);
上述连接标识符可不填写,上述语句可在前面加上@抑制错误输出或在后面加上or die()进行调试。
mysql_fetch_row()和mysql_fetch_arary()都是将sql语句返回为数组,区别是后者返回时包含字段名
mysql_query(“set names ‘GBK'”)或者是UTF-8可以解决中文编码的问题
mysql_num_rows; mysql_insert_id; mysql_tablename; mysqlerror; mysql_close

喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址