
众所周知,mysql里面有很多权限,不同权限可以使用不同功能,今天就教大家怎么获取Mysql的root权限,也就是最高权限,可以做任何事情。
1.首先使用一个没有权限的账号链接mysql,成功之后执行:show databases;这时会发现没有权限的用户只能看到一个数据库,mysql和test等数据库是看不到的;
2.如果已经安装了phpmyadmin,打开127.0.0.1/phpmyadmin,在菜单栏找到用户,然后找到没有权限的用户,点击编辑权限;
3.跳转到设置页面,找到全局权限,在全选checkbox打勾,点击右下角的执行,完成后该用户就获得了mysql数据库的所有权限;
4.再次用该账号再次链接mysql,链接成功后执行:show databases;你会发现所有数据库都会显示出来,而且使用该账号可以进行任意编辑;
6
5.也可以直接在cmd窗口命令行设置,设置权限的命令为:
REVOKE ALL PRIVILEGES ON *.* FROM 'root'@'localhost'GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0
PS:用户名部分根据自己的实际情况进行更改。
1、创建新用户通过root用户登录之后创建
>>grant all privileges on *.* to testuser@localhost identified by "123456" //创建新用户,用户名为testuser,密码为123456 ;
>>grant all privileges on *.* to testuser@localhost identified by "123456" //设置用户testuser,可以在本地访问mysql
>>grant all privileges on *.* to testuser@"%" identified by "123456" //设置用户testuser,可以在远程访问mysql
>>flush privileges //mysql 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效
2、设置用户访问数据库权限
>>grant all privileges on test_db.* to testuser@localhost identified by "123456" //设置用户testuser,只能访问数据库test_db,其他数据库均不能访问 ;
>>grant all privileges on *.* to testuser@localhost identified by "123456" //设置用户testuser,可以访问mysql上的所有数据库 ;
>>grant all privileges on test_db.user_infor to testuser@localhost identified by "123456" //设置用户testuser,只能访问数据库test_db的表user_infor,数据库中的其他表均不能访问 ;
3、设置用户 *** 作权限
>>grant all privileges on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION //设置用户testuser,拥有所有的 *** 作权限,也就是管理员 ;
>>grant select on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION //设置用户testuser,只拥有【查询】 *** 作权限 ;
>>grant select,insert on *.* to testuser@localhost identified by "123456" //设置用户testuser,只拥有【查询\插入】 *** 作权限 ;
>>grant select,insert,update,delete on *.* to testuser@localhost identified by "123456" //设置用户testuser,只拥有【查询\插入】 *** 作权限 ;
>>REVOKE select,insert ON what FROM testuser//取消用户testuser的【查询\插入】 *** 作权限 ;
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)