MySQL常用命令

MySQL

#用户管理及授权
CREATE USER luke@localhost IDENTIFIED BY 'linuxprobe';

grant all on *.* to luke@localhost;
grant select,update,delete,insert on mysql.user to luke@localhost;
#查询用户权限
show grants for luke@localhost;

#创建DB
 create database linuxprobe;
 #切换DB
 use linuxprobe;

 #创建数据表
 create table mybook (name char(15),price int,pages int);
 create table user (name char(20),age int ,gender char(3));
 #查询数据表
 show tables;

 #增加数据
 insert into mybook (name,price,pages) values ('linux','$30','621');
 insert into user (name,age,gender) values ('wangwu','25','男');

 #查询
 select * from user;
 select * from mybook where name="linux";

 #更新数据
 update user set age=28 where name="zhangsan";

 #删除数据
 delete from mybook;
 delete from user where name="zhangsan";

 #数据备份与恢复
 mysqldump -u root -p linuxprobe > /root/linuxprobeDB.dump

 mysql -u root -p linuxprobe < /root/linuxprobeDB.dump 

 #删除数据库
 drop database linuxprobe;

  

posted @ 2024-11-19 19:13  cloud-qing0212  阅读(2)  评论(0编辑  收藏  举报