MySQL(一)笔记

#Ubuntu

##Ubuntu数据库基本命令(不分大小写建议小写,结束语可以是;或者\g,退出exit)
###库级操作
1. 登录数据库:mysql -uroot -pqwe123
2. 查看库:show databases;
查看在哪个数据库里面:select database();
3. 创建用户:create user “名字”@“%” identified by“密码”;
4. 给创建用户权限:grant all on . to “创建的用户名”@“%”; # all是所有权限,*.*是所有库和所有表
5. 刷新:flush privileges;
6. 查看当前用户:select user()
7. 进入库:use mysql;
8. 查看表:show tables;
9. 查看user:select user from user
10. 删除用户:drop user (用户名);
删除库名:drop databsae (库名字);
11. 创建库:create database (库名字);
12. 查看创建库的信息:show create database (库名字);
###表级操作
1. 查看表:show tables;
2. 创建表:create table tanzhou(id int,name varchar(20))
3. 查看表信息:show create table tanzhou
desc tanzhou
4. 插入:insert into tanzhou(id,name) valuer(1,“xiaoming”)
插入:insert into tanzhou values(1,“小红”)#这必须填写全部,也可为空NULL或者默认值default
以字典形式插入:insert tanzhou set id=2,name=“fafa”
5. 查看tanzhou这个表:select * from tanzhou;
查看需要的字段:select id,name from tanzhou
加条件查看:select id,name from tanzhou where id=1; #>,<
6. 修改数据:update tanzhou set name=“haha” where id=1;
后面一定要加条件,不加条件也可以修改。
7. 删除表里面的数据:delete from tanzhou where id=1; # 删除NULL 是:where id is NULL;
8. 更改表名:alter table 表名字 rename to 要改成的表名字
9. 更改表里的字段:alter table 表名字 change column id new_id int; #把里面的id改为new_id
10. 更改里面name的类型:alter table 表名字 modify column 字段 varchar(10);
11. 增加字段:alter table 潭州 add sex int;
12. 删除字段:alter table 潭州 drop (字段类型);
13. timestamp自动储存记录修改时间

发布了13 篇原创文章 · 获赞 9 · 访问量 466

猜你喜欢

转载自blog.csdn.net/weixin_44961387/article/details/100607276
今日推荐