Mysql密码修改方法
第一种:mysqladmin
格式:mysqladmin -u用户名 -p旧密码 password 新密码 例子:mysqladmin -uroot -p123456 password 654321
第二种:SET PASSWORD
登录MySQL 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:mysql> set password for root@localhost = password('123456');
第三种:UPDATE
登录MySQL mysql> use mysql; mysql> update user set password=password('123456') where user='root' and host='localhost'; mysql> flush privileges;
第四种:忘记密码
- 第一方法
- 关闭mysql服务
[root@localhost ~]# systemctl stop mariadb
2. 运行 mysqld_safe
[root@localhost ~]# mysqld_safe --skip-grant-tables &
3.修改mysql密码
[root@localhost ~]# mysql
MariaDB >update mysql.user set authentication_string=password('654321') where user='root' and Host = 'localhost'; MariaDB [mysql]> flush privileges;
4.重启服务
[root@localhost ~]# systemctl start mariadb
- 第二方法
1. 修改my.cnf
[root@localhost ~]# vim /etc/my.cnf
[mysqld] skip-grant-tables #添加此项
2.重启服务
[root@localhost ~]# systemctl restart mariadb.service
3.修改密码
[root@localhost ~]# mysql
MariaDB [(none)]> use mysql; MariaDB [mysql]> update user set password=password('123456') where user='root'; MariaDB [mysql]> flush privileges;
4.注释my.cnf中下面参数
#skip-grant-tables
5.重启服务
[root@localhost ~]# systemctl restart mariadb.service
温馨提示:如无特殊说明,本站文章均为作者原创,转载时请注明出处及相应链接!