0.如果mysql没有初始化密码,那么首先初始化密码
mysql –u root mysql>update user set password=PASSWORD(‘123456‘) where user=‘root‘;
1.通过改表设置所有的IP可以登录
mysql -u root –p mysql>use mysql; mysql>update user set host = ‘%‘ where user = ‘root‘; mysql>select host, user from user;
使用root帐号和root的原始密码可以在任何主机登录
2.通过授权所有的IP可以登录
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION; flush privileges;
授权用户root使用密码123456从任意主机连接到mysql服务器
3.通过授权指定的IP可以登录
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘218.12.50.60‘ IDENTIFIED BY ‘mark‘ WITH GRANT OPTION; flush privileges;
授权用户root使用密码mark从指定ip为218.12.50.60的主机连接到mysql服务器:
4.权限限制
授权表达式:
grant 权限 on 数据库对象 to 用户
数据对象为 *.*:对mysql服务器中所有的数据库和表进行授权
数据对象为dbname.*:对mysql服务器中单个数据库dbname下的所有表进行授权
数据对象为dbname.user:对mysql服务器中单个数据库dbname下的user表进行授权
解除授权表达式
revoke 权限 on 数据库对象 from 用户
数据对象的界定与上面相同
mysql权限表达式
授权普通用户对数据库testdb的所有表CRUD的权限: grant select on testdb.* ‘general_user‘@‘%‘ grant insert on testdb.* to ‘general_user‘@‘%‘ grant update on testdb.* to ‘general_user‘@‘%‘ grant delete on testdb.* to ‘general_user‘@‘%‘ grant select(id,name,birth) on testdb.* ‘general_user‘@‘%‘ 可以直接使用: grant select, insert, update, delete on testdb.* to ‘general_user‘@‘%‘ 授权数据库开发人员权限: grant create on testdb.* to [email protected]‘192.168.0.%‘; grant alter on testdb.* to [email protected]‘192.168.0.%‘; grant drop on testdb.* to [email protected]‘192.168.0.%‘; grant references on testdb.* to [email protected]‘192.168.0.%‘; grant create temporary tables on testdb.* to [email protected]‘192.168.0.%‘; grant index on testdb.* to [email protected]‘192.168.0.%‘; grant create view on testdb.* to [email protected]‘192.168.0.%‘; grant show view on testdb.* to [email protected]‘192.168.0.%‘; grant create routine on testdb.* to [email protected]‘192.168.0.%‘; grant alter routine on testdb.* to [email protected]‘192.168.0.%‘; grant execute on testdb.* to [email protected]‘192.168.0.%‘; grant all privileges on testdb to [email protected]‘localhost‘
时间: 2024-10-18 17:29:52