#查看MySQL是否是运行状态
service MySQL status
开启(关闭) service mysql start(stop)
#连接MySQL
本地连接
mysql -uadmin -p
mysql -uadmin -p(密码)密码可见
远程连接
mysql -h(IP地址) -uadmin -p
exit 退出数据库管理系统
#基本操作
(命令不区分大小写,规范大写)
查看数据库
show databases
查看当前登录用户
select user()
创建数据库
create database `库名`
删除数据库
drop
#进入数据库
use 数据库名
#创建表
create table 表名(
-> `id` int,
-> `names` varchar(20),
->`sex` char(1)
->);
查看数据表
show tables
查看表结构
1 show create table 表名
innobd #表示数据库默认引擎
2 desc 表名(以表格形式输出)
#删除表
drop table 表名
##字段操作 alter
添加一个age 字段
alter table 表名 add age int;
多个
alter table 表名 add age int,add score int;
#删除字段
alter table 表名 drop age;
多个 alter table 表名 drop score,drop age;
#修改字段类型 modify
alter table 表名 modify sex varchar(20);
#修改字段名和类型 change
alter table 表名 change sex sexs char(1);
#修改表名
alter table 表名 rename 新表名;
##填写数据
#添加数据
insert into 表名 (id)
insert into 表名 (id,name,sex,age)values(1,'丸子’,‘男‘,‘18’);
insert into 表名 values (2,‘名字’,‘年龄’)“有几个字段写几个”
#修改数据
update 表名 set sexs =‘男’where id=id
#删除数据
delete from 表名 where 条件
#查看数据
select *(全部字段) from 表名