mysql的用户管理
mysql的用户管理mysql的认证有两部分:1、登陆 2、执行sql语句用来表识用户身份的,不是用户名,而是用户名加ip(kyo@1.1.1.1和kyo@2.2.2.2是两个不同身份的人)mysql记录用户密码的不是文件,而是mysql数据库下的user表(mysql.user)。>show databases;>use mysql;>show tables;>select * from user \G; //共六行数据。查看权限等信息默认用户是不是能远程登陆的,因为mysql.user中没有可以远程登陆的用户。添加远程登陆用户>show grants for root@localhost;>grant all privileges on *.* to 'mary'@'192.168.18.254'>权限global(全局)----->database(某个库)---->table(某张表)---->column(某列)global权限会表识在mysql.user表中。database权限表示在mysql.db表中。table权限标记在mysql.tables_priv表中。column权限标记在mysql.colums_priv表中。>flush privileges; //刷新权限,立即生效。>\s//可以查看登陆的用户身份,使用的哪个库,连接id,连接的服务器。登陆测试***18.254***mysql -u mary -h 192.168.18.42 -p123//可以登陆,在其他机上不能登陆all privileges //最大权限usage //最小权限,用户只能登陆,不能进行其他任何操作,test库是测试库,任何人都可以进行操作,为了安全,生产环境下,要删除test库。>grant all privileges on *.* to 't1'@'%'>>grant all privileges on vfast.* to 't2'@'%'>>grant all privileges on vfast.a to 't3'@'%'>>grant select on vfast.a to 't4'@'%'>
>grant usage on *.* to 't5'@'%'>
grant select,insert,update,delete on student.* to test2@192.168.2.12>>create database vfast;>use vfast;create table a (a int);>insert into a values (1);>flush privileges;>select * from test \G;为了安全,生产环境下,要删除test库>select * from user \G;第四行的user和password都为空,这个是匿名账号,在本地登陆。grant Create,Delete,Insert, select,Update on aixue.* to 'ttt'@'localhost'>取消权限(revoke)针对t1的所有库,所有表,取消所有权限>revoke all privileges on *.* from 't1'@'%';>show grants for 't1'@'%'; //查看具体权限,权限变成usage>revoke select,insert on test.* from 't1'@'%'; //拿走部分权限>flush privileges;删除远程登陆用户>drop user 't1'@'%';修改密码1、(主要)update mysql.user set password=password('456') where user='t5'; //修改T5密码,密码是加密的,所以用password()函数加密,t5是用户名。>flush privileges;2、>grant usage on *.* to 't5'@'%'>假如忘记了登录mysql的root用户的密码#/etc/init.d/mysqld stop手动启动数据库#mysqld_safe --skip-grant-tables --skip-networking &#mysql //登录(这种情况下,就不能使用grant来修改密码,只能用update来修改密码)>update mysql.user set password=password('123456') where user='root'; //重新修改密码#/etc/init.d/mysqld restart //重启数据库skip-grant-tables //跳过赋权表skip-networking //跳过网络#mysql -u -p //也可以登录数据库#\s//查看当前登录用户(-p@localhost)这个是匿名账号删除匿名账号记录>delete from mysql.user where user='';>flush privileges;
页:
[1]