-- 创建用户,指定明文密码
create user 'rose'@'localhost' identified by 'rosepwd';
-- 查看用户是否创建成功
select user,host from mysql.user;
-- 创建用户,不设置密码
create user 'rose01'@'localhost';
select user,host from mysql.user;
-- 查看密码的哈希值
select password('rosepwd');
-- 创建用户,使用哈希值的密码
create user 'rose02'@'localhost' identified by password '*15151B36B8E49FD6A6222C4AF15758661CFCE654';
-- 创建用户,并授予用户查询、更新数据库所有表的权限
grant select,update on *.* to 'testuser'@'localhost' identified by 'testpwd';
select user,host from mysql.user;
-- 删除用户
drop user 'testuser'@'localhost';
select user,host from mysql.user;
-- 删除用户
delete from mysql.user where user = 'rose02'and host='localhost';
select user,host from mysql.user;
-- 授予rose用户插入、查询book库所有表的权限
grant insert,select on book.* to 'rose'@'localhost';
-- 刷新系统权限表
flush privileges;
-- 授予rose01用户作用于所有库的所有表的所有权限
grant all privileges on *.* to 'rose01'@'localhost';
-- 查看用户的权限信息
show grants for 'rose'@'localhost';
show grants for 'rose01'@'localhost';
-- 回收rose用户的作用于book库所有表的插入的权限
revoke insert on book.* from 'rose'@'localhost';
flush privileges;
show grants for 'rose'@'localhost';
-- 查看日志文件的路径
show variables like 'log_error';
-- 创建新的日志信息表
flush logs;
-- 创建新的日志信息表
mysqladmin -uroot -p flush-logs
-- 备份book库
mysqldump -uroot -p book >C:mysqlbackupook_20180120.sql
-- 备份book库中的readerinfo表
mysqldump -uroot -p book readerinfo>C:mysqlbackupook_readerinfo_20180120.sql
-- 备份book和mytest库
mysqldump -uroot -p --databases book mytest>C:mysqlbackupook_mytest_20180120.sql
-- 备份所有的数据库
mysqldump -uroot -p --all-databases>C:mysqlbackupdball_20180120.sql
-- 恢复book库下的readerinfo表
mysql -uroot -p book<C:mysqlbackupook_readerinfo_20180120.sql
-- 恢复book库下的readerinfo表
use book;
source C:mysqlbackupook_readerinfo_20180120.sql
-- 使用select...into outfile导出readerinfo表的数据到readerinfo.txt这个文件
select * from book.readerinfo into outfile 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/readerinfo.txt';
-- 使用select...into outfile导出readerinfo表的数据到readerinfo.txt这个文件,并设置导出文件的格式
select * from book.readerinfo into outfile 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/readerinfo1.txt'
fields terminated by ','
lines terminated by '
';
-- 使用mysqldump命令导出book库下的bookcategory表
mysqldump -T "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads" -uroot -p book bookcategory
-- 使用mysql命令导出book库下的readerinfo表到readerinfo2.txt
mysql -uroot -p --execute="select * from readerinfo;" book > "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/readerinfo2.txt"
-- 使用load data infile命令导入readerinfo表中的数据
load data infile "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/readerinfo.txt" into table book.readerinfo;
-- 使用mysqlimport命令导入readerinfo表中的数据
mysqlimport -uroot -p book "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/readerinfo.txt"