1.方法一
vi /mysql/mysql3307.cnf
[mysqld]
skip-grant-tables ?--免密登录。
--更新密码。
mysql> update mysql.user set authentication_string=password('rootroot') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> update mysql.user set authentication_string=password('rootroot') where user='root' and host='%';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;?
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
--注释:
vi /mysql/mysql3307.cnf
#[mysqld]
skip-grant-tables
--重启数据库。
systemctl restart mysql
2.方法二
cat /var/log/mysqld.log |grep "temporary" 或者 cat /var/log/mysqld.log |grep "temporary"
--找到初始话生成的密码。
mysql -uroot -p'jdlkfjsljflsd' --使用初始化密码登录
mysql>alter user user() identified by 'rootroot'; --修改本地登陆的密码。