mysql修改root密码的多种方法
方法1: 用SET PASSWORD命令
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
方法2:用mysqladmin
mysqladmin -u root password "newpass"
如果root已经设置过密码,采用如下方法
mysqladmin -u root password oldpass "newpass"
方法3: 用UPDATE直接编辑user表
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
在丢失root密码的时候,可以这样
[root@mysql ~]# /etc/init.d/mysqld stop Shutting down MySQL. SUCCESS! [root@mysql ~]# mysqld_safe --skip-grant-tables& [1] 27426 [root@mysql ~]# 170220 18:48:38 mysqld_safe Logging to '/application/mysql/data/mysql.err'. 170220 18:48:38 mysqld_safe Starting mysqld daemon with databases from /application/mysql/data [root@mysql ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.49 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> UPDATE mysql.user SET password=PASSWORD("oldboy123") WHERE user='root'; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> exit Bye
方法四:
自己查找路径:
/etc/mysql/conf.d/
/etc/mysql/mysql.conf.d/