mysql数据库基础操作命令大全(转载)

SQL数据库语言
1.数据定义语言(CREATE,ALTER,DROP,DECLARE)
2.数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
3.数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
创建数据库
create database my-database
1
删除数据库
drop database my-database
1
创建新表
create table my_table(col1 type1 [not null] [primary key],col2,type2 [not null] [primary key],…)
1
根据已有的表创建新表
create table new_table like old_table
1
删除表
drop table my_table
1
增加一个列
列增加后不能删除。DB2中列加上后数据类型也不改变,唯一能改变的是增 加 varchar 类型的长度。

Alter table my_table add column col type
1
添加主键
Alter table my_table add primary key(col)
1
删除主键
Alter table my_table drop primary key(col)
1
创建索引
create [unique] index inx on my_table(col…)
1
删除索引
drop index inx
1
创建视图
create view my_view as select statement
1
删除视图
drop view my_view
1
常用的 sql 基本语句
选择:select * from my_table where 条件
插入:insert into my_table (field1,field2) values (value1,value2)
删除:delete from my_table where 条件
更改:update my_table set field1 = value1 where 条件
查找:select * from my_table where field1 like ‘%value1’
排序:select * from my_table order by field1,field2 [desc]
总数:select count * as totalcount form my_table
求和:select sum(field1) as sumvalue from my_table
平均:select avg(field1) as avgvalue from my_table
最大:select max(field1) as maxvalue from my_table
最小:select min(field1) as minvalue from my_table

PHP 操作 mysql 数据库
1.链接数据库

c o n n = @ m y s q l c o n n e c t ( " l o c a l h o s t " , " r o o t " , " r o o t " ) ; i f ( ! conn=@mysql_connect("localhost","root","root"); if(! conn=@mysqlconnect("localhost","root","root");if(!conn){
die(“数据库连接失败”,mysql_error())
}else{
echo"数据路连接成功"
}
1
2
3
4
5
6
2.选择数据库

mysql_select_db(“web”,$conn)
1
3.执行 sql 语句

$query=mysql_query(“select * from 表名 where 1”)
1
4.操作 sql 结果

while( r o w = m y s q l f e t c h a s s o c ( row=mysql_fetch_assoc( row=mysqlfetchassoc(result)){
print_r($row);
echo “
”;
}
1
2
3
4
5.关闭 mysql 链接

mysql_close($conn)

原文链接:https://blog.csdn.net/m0_49993061/article/details/108205550?utm_medium=distribute.pc_feed.none-task-blog-personrec_tag-20.nonecase&depth_1-utm_source=distribute.pc_feed.none-task-blog-personrec_tag-20.nonecase&request_id=5f487392ad40e5707a3fd302

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值