mysql用户密码修改,用户添加、删除、设置权限及源文件恢复数据库
2016-01-27 09:11
966 查看
一下的示例所用用户名和密码为:test,111111
Mysql密码修改:
Mysql修改密码需要root的权限,先执行mysql -uroot -p(密码);
1)使用set password方式来修改账户密码:
set password for ‘hzd’@’localhost’=password(‘newpassword’);
2)使用phpMyAdmin修改,直接用SQL语句修改mysql数据库库的user表,不过别忘了使用PASSWORD函数, 插入用户用Insert命令,修改用户用Update命令,删除用Delete命令。
mysql用户的添加和授权:
1)insert方式添加:
用户root权限登录mysql,新建test用户
mysql>Insert intomysql.user(Host,User,Password) values(‘localhost’,’test’,password(‘111111’));
刷新系统权限表 mysql> FLUSH PRIVILEGES;
如果报错
#1364 – Field ‘ssl_cipher’ doesn’t have adefault value
修改MySQL配置文件Linux系统为my.cnf,Windows系统为my.ini
修改为
重启MySQL服务
2)grant方式添加:
用户root权限登录mysql,新建test用户
mysql> grant usage on *.* to ‘test’@’localhost’identified by ‘111111’;
给test用户授权
mysql>grant all on ‘hzd’.* to ‘test’@’localhost’identified by “111111”;
这句话的意思是:授权用户’test’(其密码为111111)可以任何主机登录,可对数据库’hzd’下的所有表进行所有操作。
以下是几句关于授权的sql语句:
grant语句的语法如下:
grant privileges (columns) on what to useridentified by “password” with grant option
1)grantselect,insert on ‘*’ to test@’local’ identified by ‘111111’;
这句命令的意思是,授权用户“test”(其口令为“111111”)只能在本地localhost登录,可对任何的任何表(“*.*”前一个“*”代表任何数据库,后一个“*”代表在前个“*”的约束下的任何表)进行select,insert的操作。
2)grant update,delete on scut.student totest@"%" Identified by "123";
这句命令的意思是,授权用户“test”(其口令为“123”)可以任何主机登录,可对数据库"scut”下的表“student”进行update,delete的操作;
3)grant all on len.* to ca@"%"Identified by "123456";
这句命令的意思是,授权用户“ca”(其口令为“123456”)可以任何主机登录,可对数据库"len”下的所有表进行所有的操作;
用户删除:
drop user test@localhost
mysql授权查看:
select user from mysql.db where db="youdb"
实例:查看len数据库已经授权的用户
select user from mysql.db where db="len"
查看用户权限:
show grants for 你的用户
比如:
show grants for test@'localhost';
mysql引擎用的是innodb,现在data文件全在,如何恢复到另一个干净的环境里呢?
答:ibdata1,ib_logfile0,ib_logfile1还有其它数据库文件目录,全部复制到新的DATA目录下即可。
Mysql密码修改:
Mysql修改密码需要root的权限,先执行mysql -uroot -p(密码);
1)使用set password方式来修改账户密码:
set password for ‘hzd’@’localhost’=password(‘newpassword’);
2)使用phpMyAdmin修改,直接用SQL语句修改mysql数据库库的user表,不过别忘了使用PASSWORD函数, 插入用户用Insert命令,修改用户用Update命令,删除用Delete命令。
mysql用户的添加和授权:
1)insert方式添加:
用户root权限登录mysql,新建test用户
mysql>Insert intomysql.user(Host,User,Password) values(‘localhost’,’test’,password(‘111111’));
刷新系统权限表 mysql> FLUSH PRIVILEGES;
如果报错
#1364 – Field ‘ssl_cipher’ doesn’t have adefault value
修改MySQL配置文件Linux系统为my.cnf,Windows系统为my.ini
| sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES |
| sql_mode=NO_ENGINE_SUBSTITUTION |
2)grant方式添加:
用户root权限登录mysql,新建test用户
mysql> grant usage on *.* to ‘test’@’localhost’identified by ‘111111’;
给test用户授权
mysql>grant all on ‘hzd’.* to ‘test’@’localhost’identified by “111111”;
这句话的意思是:授权用户’test’(其密码为111111)可以任何主机登录,可对数据库’hzd’下的所有表进行所有操作。
以下是几句关于授权的sql语句:
grant语句的语法如下:
grant privileges (columns) on what to useridentified by “password” with grant option
1)grantselect,insert on ‘*’ to test@’local’ identified by ‘111111’;
这句命令的意思是,授权用户“test”(其口令为“111111”)只能在本地localhost登录,可对任何的任何表(“*.*”前一个“*”代表任何数据库,后一个“*”代表在前个“*”的约束下的任何表)进行select,insert的操作。
2)grant update,delete on scut.student totest@"%" Identified by "123";
这句命令的意思是,授权用户“test”(其口令为“123”)可以任何主机登录,可对数据库"scut”下的表“student”进行update,delete的操作;
3)grant all on len.* to ca@"%"Identified by "123456";
这句命令的意思是,授权用户“ca”(其口令为“123456”)可以任何主机登录,可对数据库"len”下的所有表进行所有的操作;
用户删除:
drop user test@localhost
mysql授权查看:
select user from mysql.db where db="youdb"
实例:查看len数据库已经授权的用户
select user from mysql.db where db="len"
查看用户权限:
show grants for 你的用户
比如:
show grants for test@'localhost';
mysql引擎用的是innodb,现在data文件全在,如何恢复到另一个干净的环境里呢?
答:ibdata1,ib_logfile0,ib_logfile1还有其它数据库文件目录,全部复制到新的DATA目录下即可。
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复