$ vim /etc/my.cnf
#======================[mysqld]validate_password=off
#======================
3. 修改密码: 推荐临时通用密码 My#123.com
sql
1
2
3
SET PASSWORD FOR'用户名'@'主机名'=PASSWORD('新密码');
-- 或
ALTERUSER'用户名'@'主机名' IDENTIFIED BY'新密码';
4. 忘记Root密码
shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#1. 在/etc/my.cnf的[mysqld]段添加如下内容[mysqld]skip-grant-tables
#2. 启动服务$ systemctl restart mysqld
#4.无需用户名和密码,直接登录mysql,并修改密码$ mysql
mysql> update mysql.user setauthentication_string=password('123456') where user='root';
#mysql> update mysql.user set password=password('123456') where user='root' and host='localhost'; # v5.6mysql> FLUSH PRIVILEGES;
#4. 删除第一步的skip-grant-tables,再次重启服务$ systemctl restart mysqld
#5. 密码已找回,密码登录$ mysql -uroot -p123456
三. 权限管理
1. 查看权限
privileges:意为特权,权限
sql
1
SHOWGRANTFOR'用户名'@'主机名';
2. 授予权限:grant to
WITH GRANT OPTION:表示该用户可以继续将自己拥有的权限授权给别人。
shell
1
2
3
4
5
GRANT <权限列表> ON 数据库名.表名 TO '用户名'@'主机名'[IDENTIFIED BY '密码'][WITH GRANT OPTION];
FLUSH PRIVILEGES;
# [WITH GRANT OPTION]查看Grant_priv是否为YSELECT host,user,Grant_priv FROM mysql.user;
3. 远程访问:
当用户不存在时创建用户,并授权
shell
1
2
GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'My#123.com' WITH GRANT OPTION;
FLUSH PRIVILEGES;
评论