MySQL 8.0数据库添加用户和授权

1. 创建新用户 create user 'username'@'host' identified by 'password'; 其中username为自定义的用户名;host为登录域名,%代表任意IP,localhost代表本机,或者填写指定的IP地址;password为密码 2. 为用户授权 grant all privileges on *.* to 'username'@'host' with grant option; 其中*.*第一个*表示所有数据库,第二个*表示所有数据表,如果不想授权全部那就把对应的*写成相应数据库或者数据表;username为指定的用户;%为该用户登录的域名 3. 授权之后刷新权限 flush privileges; 4. 撤销授权 # 收回权限(不包含赋权权限) revoke all privileges on *.* from user_name; revoke all privileges on user_name.* from user_name; # 收回赋权权限 revoke grant on option on *.* from user_name; # 操作完成后重新刷新权限 flush privileges;

发布于 2024-09-05 · 上次修改 2026-01-12 · 1 分钟 · 58 字 · 流逝光

MySQL 修改用户

具体操作 在5.7之前修改密码:(使用update修改user表) use mysql; update user set authentication_string=password('123456') where host = 'localhost' and user='root'; 在5.7修改密码:(废除了password字段,需要使用authentication_string) use mysql; update user set password=password('123456') where host='localhost' and user ='root' 在8.0中已经不能使用password函数和set…语句,只能使用 use mysql; alter user 'root'@'localhost' identified with mysql_native_password by '123456'; ## 如果遇报错,先执行flush privileges 原因 mysql5.7.9版本之后废弃了password字段和password()函数,且默认加密方式不采用mysql_native_password. 在mysql8.0以上版本中caching_sha2_password和sha256_password认证插件比mysql_native_password插件提供的密码加密更安全,并且前者加密性能更好。由于caching_sha2_password这样优秀的安全和性能特征,让他作为mysql8.0的默认首选认证插件,而并不是mysql_native_password. 所以mysql8.0默认是caching_sha2_password加密,5.7.9版本后的默认是mysql_native_password.

发布于 2024-09-05 · 上次修改 2024-07-25 · 1 分钟 · 44 字 · 流逝光