一、库的操作
1、查看所有的数据库名称
Show databases;
2、创建新的数据库
Create database test;
3、查看数据库的属性
show create database test;
4、进入数据库
use test;
5、删除数据库
drop database tes1t;
二、数据表的操作
1、查看当前数据库下所有的数据表名称
Show tables;
2、创建新的数据表
Create table 数据表名(字段名);
例: create table tb_demo1 (id int(5),name varchar(20),ipone int(11));
3、查看数据表的属性
desc 数据表名;
例:
mysql> desc tb_demo1;
4、修改数据表
ALTER TABLE <表名> [修改选项]
(1)新增列
ALTER TABLE table_name ADD [COLUMN] col_name column_defination [FIRST(之前) | AFTER(之后)] col_name;
例:alter table tb_demo1 add passwd varchar(10);
(2)删除列
ALTER TABLE table_name DROP [COLUMN] col_name;
例:alter table tb_demo1 drop sessonid2;
(3)修改字段名
ALTER TABLE table_name change old_col_name new_col_name new_column_defination;
例:alter table tb_demo1 change id uid int(5);
(4)修改表名
ALTER TABLE table_name rename new_table_name;
alter table tb_demo1 rename tbdemo;
5、删除数据表
drop table table_name;
例:drop table tb_test;
三、数据操作
1、在数据表中插入数据
(1)方法1:insert into table_name (col_name1,col_name2,col_name3) values (value1,value2,value3); //字符串需要加单引号
例:insert into tb_demo (uid,name,passwd) values (1,‘zhang’,123);
(2)方法2:insert into table_name set col_name=value
例:insert into tb_demo set uid=2,name=‘wang’,passwd=‘admin@123’;
2、修改数据表中的数据
update table_name set col_name=‘value’ where col_name=value;
例:update tb_demo set name=‘meng’ where uid=1;
3、删除数据表中的数据
删除单个表中的数据:
DELETE FROM table_name [WHERE 子句] [ORDER BY 子句] [LIMIT 子句]
例:delete from tb_demo where uid=1;
4、查询数据表中的数据
select col_name from table_name;
例:select * from tb_demo;