查看MYSQL数据库中所有用户的远程权限 mysql>use mysql; mysql>select host, user from user; 或者 mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; 查看数据库中具体某个用户的执行权限 mysql>show grants for root@localhost;
1、使用 root 管理员登陆 mysql mysql -uroot -p123456; 或者 mysql -h192.168.1.1 -ua1 -p123456; 2、创建新用户 create user a1@localhost identified by '123456'; #创建只能本地登陆的用户
'%' - 所有情况都能访问
‘localhost’ - 本机才能访问 111.222.33.44 - 指定 ip 才能访问 注:修改密码 set global validate_password_policy=0;
update mysql.user set password=password('新密码') where user='user1'; update mysql.user set authentication_string=password('新密码') where user='user1'; #mysql5.版本以上 alter user user() identified by 'password'; #一般修改过密码都要用这个命令再次修改一次密码
这个时候访问,是除了默认生成的两个数据库,看不到任何其它的数据库: 3、给某用户添加远程权限 用update命令: mysql>use mysql; mysql>update user set host = '%' where user = 'a1'; #给a1增加任何ip远程权限
用grant 命令添加具体执行权限: grant all on 想授权的数据库.* to a1@'%'; #给任何ip所有权限 grant all on 想授权的数据库.* to a1@localhost; #给localhost所有权限 grant all on 想授权的数据库.* to a1@localhost identified by '123456'; #同时创建用户并授权 注意:用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令: grant on 想授权的数据库. to a1@localhost identified by ‘123456’ with grant option; grant select on 想授权的数据库.* to a1@localhost identified by '123456'; #给select权限 4、删除用户 delete from mysql.user where user='a1'; 四、刷新 flush privileges; 分享:
温馨提示:数据库名不可以数字开头!!!!!
忘记mysql密码如何进mysql?
vi /etc/my.conf [mysqld] 增加 skip-grant-tables
















