添加新用户
添加用户时应该切换到授权的数据库下
Code
mysql>create user 'test'@'localhost' identified by '123456'; |
- 允许外网ip访问 Code
mysql>create user 'test'@'%' identified by '123456';
- 刷新授权 Code
mysql>flush privileges;
- 授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限) Code
mysql>grant all privileges on testDB.* to test@localhost identified by '1234';
- 如果想指定某库的部分权限给某用户本地操作,可以这样来写: Code
mysql>grant select,update on testDB.* to test@localhost identified by '1234';
- 授权test用户拥有所有数据库的某些权限的远程操作: Code
mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";
- 使用以下命令删除用户 Code
delete from user where user='账户名';
ERROR 1046 (3D000): No database selected
use mysql//再删除 - 修改指定用户密码: Code
mysql>update mysql.user set password=password('新密码') where User="test" and Host="localhost";
mysql>flush privileges; - 撤销已经赋予用户的权限 Code
mysql>revoke all on *.* from dba@localhost;
增删改查
sql连接mysql服务器
mysql -uroot -p
创建数据库test1
create database test1;
显示有哪些数据库
show databases;
//mysql 自动创建的表有
information_schema:主要存储了系统中的一些数据库信息,比如用户表信息、列信息、权限信息、字符集信息、分区信息等等
cluster:存储了系统的集群信息
mysql:存储了系统的用户权限信息。
test:系统自动创建的测试数据库,任何用户都可以访问
选择数据库
use test1
显示test1数据库中创建的所有表
show tables
删除数据库
drop database test1;
创建表
create table emp(ename varchar(10),hiredata date,sal decimal(10,2),deptno int(2));
查看表定义
desc emp;
查看创建表的定义
show create table emp;
删除表
drop table emp;
修改表
alter table emp modify ename varchar(20);
增加表字段
alter table emp add column age int(3);
删除表字段
alter table emp drop column age;
字段改名
alter table emp change age age1 int(4);
change 和modify都可以修改表的定义,不同的是change后面需要写两次列名,不方便,但是change的优点是可以修改列名称,则modify则不能
修改字段排序
alter table emp add birth date after ename;
alter table emp modify age int(3) first;
更改表名
alter table emp rename emp1;连接
mysql
mysql1