普歌-码灵团队:MySQL技术数据库基础操作命令大全,建议收藏呐~

MySQL - 常用操作

& 创建数据库

create database database01

& 删除数据库

drop database database

& 创建新表

create table table(col type[not null])

& 删除表

drop table table

& 增加列

Alter table table add column col type

&添加主键

Alter table table add primary key(col)

&删除主键

Alter table table drop primary key(col)

&创建索引

create [unique] index inx on table(col…)

&删除索引

drop index inx

&创建视图

create view my_view as select statement

&删除视图

drop view my_view

MySQL - 基本语句

  • 选择:

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

MySQL - PHP操纵

  1. 链接数据库
  $conn=@mysql_connect("localhost","root","root");if(!$conn){ die("数据库连接失败",mysql_error())}else{ echo"数据路连接成功"}123456
  1. 选择数据库
  mysql_select_db("web",$conn)1
  1. 执行sql语句
  $query=mysql_query("select * from 表名 where 1")1
  1. 操作sql结果
  while($row=mysql_fetch_assoc($result)){ print_r($row); echo "<br>";}1234
  1. 关闭sql链接
  mysql_close($conn)

作者:Aimee.洁
本文版权归作者和CSDN共有,欢迎转载,未经作者同意必须保留此版声明,否则保留追究法律责任的权利。

@喜欢的点赞关注,评论区留下宝贵的意见呐❥❥~

猜你喜欢

转载自blog.csdn.net/weixin_52606478/article/details/113764314