平台:windows 10
mysql:5.7.22
第一:不需要密码直接进入mysql。
安装mysql,windows 默认不设置密码,以ODBC@默认用户名,直接登陆。
通过命名SELECT USER();看已看到用户名:ODBC@ 。
但是SELECT user FROM mysql.user;可以看到只有这三个用户:
===================================================
正常操作,我们可以删掉特定用户
1、执行以下语句:删除特定用户
DELETE FROM user where user='abc';
2、在执行以下语句:刷新用户
FLUSH privileges;
3、重启mysql
完成删除
====================================================
第二:怎样设置凭密码登陆?
root用户设置登陆密码123456,新版本的mysql 的新加authentication_string代替以前的password。
1、设置密码
update mysql.user set authentication_string =password('123456') where user='root';
或者
alter user 'root'@'localhost' identified by '123456';
2、刷新
FLUSH PRIVILEGES
第三:设置了密码,为啥任意登陆???
#正常情况,当设置号密码后,就不可以直接登陆了,也就是屏蔽了ODBC@这个默认的用户名了。
#发现一个问题,重启mysql后,都要刷新flush privileges,才能确保非密码用户不可登陆。
不知道为啥?
**********************************************************************
#电脑重启即可生效
+++++++++++++++++++++++++++++++++++++++++++
正式原因找到了,windows 安装文件my.ini,中默认有这个语句:skip-grant-tables。
这个语句执行的结果,就是跳过授权表,意思不言而喻。
我们要做的事
1、mysql -u root -p
2、进入root账号下,然后执行
update mysql.user set authentication_string = password('123456') where user='root';
3、刷新 flush privileges;
4、然后,把my.ini 中的skip-grant-tables语句注释掉;
5、重启mysql;
目前看来事解决了不需要密码 /任意用户直接登陆
+++++++++++++++++++++++++++++++++++++++++++
**********************************************************************
第四:新增加本地用户
1、创建用户名
create user 'JESS'@'localhost' identified by '123456';
create user 'jess'@'%" identified by '123'; %表示任何链接,不仅仅是本地localhost。
2、为新用户创建数据库
create database 'jess_db' default charset utf8 collate utf8_general_ci;
collate utf8_general_ci 数据库的校验规则,意思大小写不敏感。
其他规则:utf8_bin 区分写敏感;
utf8_general_ci 大小写不敏感
utf8_genral_cs 大小写敏感
其中ci是case insensitive 缩写,cs 是case sensitive。
3、授权JESS用户对jess_db数据库拥有所有权限
授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by '密码
grant all privileges on `jess_db` .* to
'JESS'@'localhost' identified by '123456';
4、刷新
flush privileges
第五:新增用户权限修改
1、以root用户身份登陆
2、撤销JESS用户对jess_db数据库的权限
revoke all privileges on `jess_db'.* from 'JESS'@'localhost';
3、刷新
flush privileges
4、授权JESS用户对所有数据库的权限
grant all privileges on *.* to 'JESS'@'localhost' indentified by '123456';
刷新 flush privileges
5、指定针对jess_db数据库部分select 和update权限给jess用户,其他不开放
【增:insert 删 :delete 改: update 查:select】
grant select,update on `jess_db`.* to 'jess'@'local' identified by '123456';
刷新 flush privileges
第六:查看用户被授予的权限
select * from mysql.user where user='Jess'\G
\G后面不能再加分号;,因为\G在功能上等同于;,如果加了分号,那么就是;;(2个分号),SQL语法错误