方法一 用set password
mysql> set password for '用户名'@'localhost' = password '新密码';
例子 :mysql>set password for root@localhost = password 'password';
方法二 用mysqladmin
mysqladmin -uroot -p旧密码 password 新密码;
方法三 用update直接修改user表
密码丢失的情况下>>>>vim /etc/my.cnf
在[mysqld]下面添加一条
skip-grant-tables
重启mysql服务
systemctl restart mysqld
mysql 就可以直接进入mysql中或者是mariadb
mysql中:
mysql> update mysql.user set authentication_string=password('新密码') where user='root'
mariadb中:
mysql> update mysql.user set password=password('新密码') where user='root'
方法四 用alter
mysql> alter mysql.user '用户名'@'登入主机' identified by '密码'
例子: mysql> alter mysql.user 'root'@'localhost' identified by 'password'