mariadb password
# root 忘记密码
- 先停掉 mysql 服务
systemctl stop mariadb
1
- 使用跳过授权的方式启动 mariadb
mysqld_safe --skip-grant-tables &
1
- 当跳过授权启动时,可以不需要密码直接登陆数据库。登陆更新密码即可
mysql
1
- 关闭跳过授权启动的进程
systemctl stop mariadb
1
- 正常启动 mariadb
systemctl start mariadb
1
# 用户与密码
- 创建用户
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password1';
// OR
CREATE USER 'username'@'%' IDENTIFIED BY 'password1';
1
2
3
2
3
- 分配(移除)权限
# 分配权限
GRANT ALL ON yourDB.* TO 'username'@'localhost';
// OR
GRANT ALL ON yourDB.* TO 'username'@'%';
// OR,注意当数据库有特殊字符时,需要使用 ` 包裹
GRANT ALL ON `your-db`.* TO 'username'@'%';
# 移除权限, to 和 from 的区别
revoke ALL ON `your-db`.* from 'username'@'%';
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
- 写入权限,以使用户密码、权限立即生效
FLUSH PRIVILEGES;
1
- 删除用户
DROP USER 'username'@'host'
1
编辑 (opens new window)
上次更新: 2024/01/17, 10:57:24