1.停用mysql
2.使用skip-grant-tables参数启动
3.update语句更新密码
4.重开mysql,正常登录密码更改后的mysql
1.停用mysql
#停用mysql 如若没有密码也只能killall mysqld ,这里我有密码只是演示所以还是平滑关闭
[root@master01 bin]# mysqladmin -uroot -poracle -S /data/3307/mysql.sock shutdown
[root@master01 bin]# netstat -lntup|grep 330
2.使用skip-grant-tables参数启动
#使用skip-grant-tables参数启动mysql,忽略授权登录验证
[root@master01 bin]# mysqld_safe --defaults-file=/data/3307/my.cnf --skip-grant-tables --user=mysql
#无密码方式登录mysql
[root@master01 bin]# mysql -uroot -S /data/3307/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.39-log Source distribution
Copyright (c) 2000, 2014, 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.
#利用update 语句更新用户密码
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
3.update语句更新密码
mysql> update user set password=password('oracle123456') where user='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
4.重开mysql,正常登录密码更改后的mysql
#使用更新密码关闭mysql并开启
[root@master01 ~]# mysqladmin -uroot -poracle123 -S /data/3307/mysql.sock shutdown
#启动mysql 3307
[root@master01 bin]# mysqld_safe --defaults-file=/data/3307/my.cnf --user=mysql
#登录mysql
[root@master01 bin]# mysql -uroot -S /data/3307/mysql.sock -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.39-log Source distribution
Copyright (c) 2000, 2014, 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.
OK
2.使用skip-grant-tables参数启动
3.update语句更新密码
4.重开mysql,正常登录密码更改后的mysql
1.停用mysql
#停用mysql 如若没有密码也只能killall mysqld ,这里我有密码只是演示所以还是平滑关闭
[root@master01 bin]# mysqladmin -uroot -poracle -S /data/3307/mysql.sock shutdown
[root@master01 bin]# netstat -lntup|grep 330
2.使用skip-grant-tables参数启动
#使用skip-grant-tables参数启动mysql,忽略授权登录验证
[root@master01 bin]# mysqld_safe --defaults-file=/data/3307/my.cnf --skip-grant-tables --user=mysql
#无密码方式登录mysql
[root@master01 bin]# mysql -uroot -S /data/3307/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.39-log Source distribution
Copyright (c) 2000, 2014, 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.
#利用update 语句更新用户密码
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
3.update语句更新密码
mysql> update user set password=password('oracle123456') where user='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
4.重开mysql,正常登录密码更改后的mysql
#使用更新密码关闭mysql并开启
[root@master01 ~]# mysqladmin -uroot -poracle123 -S /data/3307/mysql.sock shutdown
#启动mysql 3307
[root@master01 bin]# mysqld_safe --defaults-file=/data/3307/my.cnf --user=mysql
#登录mysql
[root@master01 bin]# mysql -uroot -S /data/3307/mysql.sock -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.39-log Source distribution
Copyright (c) 2000, 2014, 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.
OK