MySql 用户创建,添加,修改,删除,授权

xiaoxiao2025-08-02  25

一  、新建用户

1,以root用户登录进去   eg:mysql  -用户名  -p 密码

mysql -u root -p

密码:123456;

查看用户

select user,host  from mysql.user;

2.创建新的用户

insert into mysql.user(host,user,password) values("localhost","用户名",password("123456"));

localhost:只能本地登录,如需远程登录只需修改成"%"

如果出现: Field 'ssl_cipher' doesn't have a default value     错误,找到mysql的配置文件mysql.ini 把其中的

sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER

修改成

sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER

重启服务

二、为用户授权

grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";

1,为用户授予所有权限

grant all privileges on *.* to test@localhost identified by '123456';

flush privileges;//刷新权限

2.为用户授予部分权限

grant select,update on *.* to test@localhost identified by '123456';

flush privileges;//刷新权限

3.为用户授予指定数据库权限

grant all privileges on testData.* to test@localhost identified by '123456';

testData: 自己创建的数据库

三、修改

update mysql.user set password=password('新密码') where user="test" and host="localhost";

四、删除用户

Delete FROM user Where user='test' and host='localhost';

 

列出所有的数据库

show database;

切换数据库

user 库名;

 

转载请注明原文地址: https://www.6miu.com/read-5034141.html

最新回复(0)