目录
进入mysql数据库:
首先进入mysql的bin目录,然后输入命令mysql -u root -p
输入密码password,即可进入mysql
退出mysql:
mysql> exit
Bye
查看数据库:(不要忘记分号)
mysql> show databases;
创建数据库:
mysql> CREATE DATABASE DemoDatabase;
删除数据库:
mysql> drop database demodatabase;
删除数据库的第二种方法:
E:\Environment\mysql-8.0.25-winx64\bin>mysqladmin -u root -p drop demodatabase
选择数据库:
mysql> use user
当出现Database changed时,说明该数据库已经被选中,后续所有的操作都是在该数据库中完成。
mysql数据类型:
创建数据表:
mysql> create table if not exists
runoob_tb1
(
->runoob_id
int unsigned auto_increment,
->runoob_title
varchar(100) not null,
->runoob_author
varchar(40) not null,
->submission_date
DATE,
-> PRIMARY KEY(runoob_id
)
-> )ENGINE=iNNOdb default charset=utf8;
unsigned:非负数
auto_increment:自增
删除数据表:
mysql> drop table runoob_tb1;
显示当前打开的数据库:
mysql> select database();
插入数据:
mysql> insert into teacher(id,age,name) values (1,23,"李冰");
查询数据:
mysql> select * from teacher;
mysql> select * from id=1;
mysql> select * from teacher where id=1;
更新数据:
mysql> update teacher set age=35 where id=1;
删除数据:
mysql> delete from teacher where id=3;
模糊查询:
mysql> select * from teacher where name like '%王%';
mysql> select * from teacher where name like '王%';
联合查询:
mysql> select name from student
-> union
-> select name from teacher
排序:
mysql> select * from student order by id asc;
mysql> select * from student order by id desc;
分组:
mysql> select age,count(*) from student group by age;