创建表:create table students ( id int unsigned not null auto_increment primary key, name char(8) not null, sex char(4) not null, age tinyint unsigned not null, tel char(13) null default "-" );
插入数据:使用insert语句如:insert into students values(NULL, "王刚", "男", 20, "13811371377");
查询数据:使用select语句,如:select name, age from students; 或 select * from students; 使用通配符 * 可查询所有列。
条件查询:使用where关键字,如:select * from students where sex="女"; 查询特定条件数据。
更新数据:使用update语句如:update students set tel=default where id=2; 更新指定列数据。
删除数据:使用delete语句如:delete from students where id=2; 删除指定数据。
表修改:使用alter table语句添加、修改、删除列,如:alter table students add address char(60); 或alter table students drop birthday;。
重命名表:使用alter table表名 rename 新表名;。
删除表:使用drop table 表名;。
删除数据库:使用drop database 数据库名;。
创建用户:使用命令CREATE USER 'lxk'@'localhost' identified by 'lxk';,并授权grant all privileges on lxk. to 'lxk'@'localhost';,刷新系统权限表flush privileges;。