# 任何ip的客户端都可以访问 create user 'tester'@'%' identified by '123456'; # 只有本地的客户端才可以访问 create user 'tester'@'localhost' identified by '123456'; # 只有指定的192.168.1.90这个ip才可以访问 create user 'tester'@'192.168.1.90' identified by '123456'; 2、修改用户
(1)修改密码
update mysql.user set authentication_string=password('新密码') where user='tester' and host='localhost'; # 5.7版本使用 update mysql.user set password=password('新密码') where user='tester' and host='localhost'; # 5.6版本使用 (2)修改host
update mysql.user set host='192.168.1.100' where user='tester'; (3)修改用户后需要刷新硬盘或重启数据库才生效;其中刷新硬盘需要有reload权限
GRANT reload ON *.* to 'root'@'%'; (4)删除用户
DELETE FROM mysql.user WHERE user='tester' and host='localhost'; (5)忘记密码的重置流程
1)在/etc/my.cnf 加入skip-grant-tables跳过授权表
2)重启MySQL,后无密码登录
3)修改密码
update mysql.user set authentication_string=password('root') where user='root'; 4)在/etc/my.cnf删除skip-grant-tables
5)重启MySQL,输入密码进入
二、权限管理
1、权限授予
(1)查询用户权限
SHOW GRANTS FOR tester; SELECT * FROM mysql.user WHERE user='tester' /G (2)授予权限
GRANT ALL PRIVILEGES ON *.* TO 'tester'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; (3)撤销权限
REVOKE ALL PRIVILEGES ON *.* FROM 'tester'@'%'; 2、账号权限体系
(1)服务级用户权限
GRANT ALL PRIVILEGES ON *.* TO 'tester'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; (2)数据库级用户权限
GRANT ALL PRIVILEGES ON staff.* TO 'tester'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; (3)表级用户权限
GRANT ALL PRIVILEGES ON staff.employee TO 'tester'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; (4)字段级用户权限
三、表空间管理(InnoDB)
(1)共享表空间(默认)
数据和文件都存放在data目录下的ibdata1文件里,多数据共用一个。
查看共享表空间大小和存放路径:
show variables like 'innodb_data%'; (2)独占表空间
每个数据库都有自己的文件夹和文件
.frm保存元数据,表结构,表结构的定义
.ibd存放数据和索引文件
查看value为ON,则开启了独占表空间:
show variables like 'innodb_file_per_table'; 四、备份与还原
select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),' MB') as data_size, concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size from information_schema.tables group by TABLE_SCHEMA ORDER BY data_size desc; #order by data_length desc;