启动、重启、停止:service mysqld start/restart/stop
查看mysql状态、以及mysql的pid码: service mysqld status
设置mysql密码:mysqladmin -uroot -password”123456”
登录:mysql -uroot -p123456
退出:exit/ctrl+c
查看所有数据库:show databases;
切换数据库:use dcs65;
查看目前所处数据库:select database();
新建数据库:create database dcs65; create database if not exist dcs65;
删除数据库:drop database dcs65; drop database if exist dcs65;
查看数据库中所有表:show tables;
查看表结构:desc test1;
修改表名:alter table rename test1 test;
修改字段名并取消自增长约束:alter table test1 change id sid int(20);
修改字段名并添加自增长约束:alter table test1 change sid id int(20)auto_increment;
添加字段到首位:alter table test1 add class int(20)first;
添加字段到某个字段后:alter table test1 add sex int(20) after id;
修改某个字段的位置:alter table test1 modify class int(20)after id;
添加两个字段:alter table test1 add(age1 int(20),age2 int(20));
删除表中字段:alter table test1 drop sex;
同时删除多个字段:alter table drop age1,drop age2;
删除字段的自增约束:alter table test1 change id id int(20);
删除字段的主键约束:alter table test1 drop primary key;
添加主键及自增约束:alter table test1 change id id int(20) primary key auto_increment;
删除表:drop table test1;
新建表:create table test1(id int(20) primary key auto_increment,score float(20,2) not null,name varchar(20),phone bigint(20) default 13577778888,time date)
查看表中所有内容:select * from test;
插入数据:insert into test1(id,score,name,phone,time() values(2,99,’xiaoer’,13577778888,’2021-08-07’)