一、创建一个数据库
-- study_lsl 为数据库名称 --
mysql> CREATE DATABASE study_lsl;
二、使用root创建一个用户
-- 使用root 创建名为 guest_test 用户,密码为“root”
create user guest_test@localhost identified by "root";
二、为新用户赋予权限
1、赋予用户名为guest_test,对数据库study_lsl 进行增删改功能
grant create,alter,drop on study_lsl.* to guest_test@localhost
3、可以使用navicat通过guest_test的用户名与密码进行连接
3、赋予用户名guest_test,study_lsl数据库中所有表查询权限
grant select on study_lsl.* to guest_test@localhost
4、赋予guest_test用户,study_lsl数据库中所有表全部权限
grant all privileges on study_lsl.* to guest_test@localhost
5、给guest_test用户赋予study_lsl数据库中某个表的用户权限
grant select on guest_test.表名 to guest_test@localhost
6、撤销guest_test用户study_lsl库所有表的增删改查的权限
revoke select,update,delete,insert on study_lsl.* from guest_test@localhost;
flush privileges;
7、删除guest_test用户
drop user guest_test@localhost
三、对数据库中列进行操作
1、添加列
在proudec_order_extend表中新添加cost列
-- 新添加的列只能是允许为空 --
alter table proudec_order_extend add cost INT(8) NULL;
2、修改字段长度或字段类型
-- 调整列的字段长度或字段类型 --
alter table proudec_order_extend modify cost CHAR(16) NULL;
3、修改列名
-- 修改数据表proudec_order_extend的cost列的列名为cots1 --
ALTER TABLE proudec_order_extend RENAME COLUMN cost TO cost1;
4、删除列
-- 删除数据表中的列 --
Alter table proudec_order_extend drop cost1;