taosim


killall -TERM mysqld
/bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/orgorz.pid --skip-grant-tables &
/bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/orgorz.pid &

update user set password=password(\'company\') where user=\'root\';
flush privileges;
新开一个ssh标签窗口,尝试连接如:
[root@orgorz ~]# mysql -uroot -p

mysql> select host,user,password from user where user=\'root\';
+------+------+-------------------------------------------+
| host | user | password |
+------+------+-------------------------------------------+
| % | root | *663771E441F302F925EAAFEF7B8DA65688E60556 |
+------+------+-------------------------------------------+
1 row in set (0.00 sec)

mysql>

 

======================================

 

[root@orgorz ~]# killall -TERM mysqld
[root@orgorz ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.14-log MySQL Community Server (GPL)

Copyright (c) 2000, 2010, 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> quit
Bye
[root@orgorz ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.14-log MySQL Community Server (GPL)

Copyright (c) 2000, 2010, 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> 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
mysql> desc user;
+------------------------+-----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum(\'N\',\'Y\') | NO | | N | |
| Insert_priv | enum(\'N\',\'Y\') | NO | | N | |
| Update_priv | enum(\'N\',\'Y\') | NO | | N | |
| Delete_priv | enum(\'N\',\'Y\') | NO | | N | |
| Create_priv | enum(\'N\',\'Y\') | NO | | N | |
| Drop_priv | enum(\'N\',\'Y\') | NO | | N | |
| Reload_priv | enum(\'N\',\'Y\') | NO | | N | |
| Shutdown_priv | enum(\'N\',\'Y\') | NO | | N | |
| Process_priv | enum(\'N\',\'Y\') | NO | | N | |
| File_priv | enum(\'N\',\'Y\') | NO | | N | |
| Grant_priv | enum(\'N\',\'Y\') | NO | | N | |
| References_priv | enum(\'N\',\'Y\') | NO | | N | |
| Index_priv | enum(\'N\',\'Y\') | NO | | N | |
| Alter_priv | enum(\'N\',\'Y\') | NO | | N | |
| Show_db_priv | enum(\'N\',\'Y\') | NO | | N | |
| Super_priv | enum(\'N\',\'Y\') | NO | | N | |
| Create_tmp_table_priv | enum(\'N\',\'Y\') | NO | | N | |
| Lock_tables_priv | enum(\'N\',\'Y\') | NO | | N | |
| Execute_priv | enum(\'N\',\'Y\') | NO | | N | |
| Repl_slave_priv | enum(\'N\',\'Y\') | NO | | N | |
| Repl_client_priv | enum(\'N\',\'Y\') | NO | | N | |
| Create_view_priv | enum(\'N\',\'Y\') | NO | | N | |
| Show_view_priv | enum(\'N\',\'Y\') | NO | | N | |
| Create_routine_priv | enum(\'N\',\'Y\') | NO | | N | |
| Alter_routine_priv | enum(\'N\',\'Y\') | NO | | N | |
| Create_user_priv | enum(\'N\',\'Y\') | NO | | N | |
| Event_priv | enum(\'N\',\'Y\') | NO | | N | |
| Trigger_priv | enum(\'N\',\'Y\') | NO | | N | |
| Create_tablespace_priv | enum(\'N\',\'Y\') | NO | | N | |
| ssl_type | enum(\'\',\'ANY\',\'X509\',\'SPECIFIED\') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | YES | | | |
| authentication_string | text | YES | | NULL | |
+------------------------+-----------------------------------+------+-----+---------+-------+
42 rows in set (0.00 sec)

mysql> select * from user where user=\'root\';
+------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------
+-------------+---------------+--------------+-----------+------------+-----------------+------------
+------------+--------------+------------+-----------------------+------------------+--------------
+-----------------+------------------+------------------+----------------+---------------------
+--------------------+------------------+------------+--------------+------------------------+----------
+------------+-------------+--------------+---------------+-------------+-----------------
+----------------------+--------+-----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv |
Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv |
Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv |
Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv |
Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer |
x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin |
authentication_string |
+------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------
+-------------+---------------+--------------+-----------+------------+-----------------+------------
+------------+--------------+------------+-----------------------+------------------+--------------
+-----------------+------------------+------------------+----------------+---------------------
+--------------------+------------------+------------+--------------+------------------------+----------
+------------+-------------+--------------+---------------+-------------+-----------------
+----------------------+--------+-----------------------+
| % | root | mimacut | Y | Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y
| Y | Y | | | | | 0 |
0 | 0 | 0 | | |
+------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------
+-------------+---------------+--------------+-----------+------------+-----------------+------------
+------------+--------------+------------+-----------------------+------------------+--------------
+-----------------+------------------+------------------+----------------+---------------------
+--------------------+------------------+------------+--------------+------------------------+----------
+------------+-------------+--------------+---------------+-------------+-----------------
+----------------------+--------+-----------------------+
1 row in set (0.00 sec)

mysql> update user set password=password(\'company\') where user=\'root\';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from user where user=\'root\';
+------+------+-------------------------------------------+-------------+-------------+-------------
+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------
+-----------------+------------+------------+--------------+------------+-----------------------
+------------------+--------------+-----------------+------------------+------------------+----------------
+---------------------+--------------------+------------------+------------+--------------
+------------------------+----------+------------+-------------+--------------+---------------+-------------
+-----------------+----------------------+--------+-----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv
| Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv
| Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv |
Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv
| Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer |
x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin |
authentication_string |
+------+------+-------------------------------------------+-------------+-------------+-------------
+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------
+-----------------+------------+------------+--------------+------------+-----------------------
+------------------+--------------+-----------------+------------------+------------------+----------------
+---------------------+--------------------+------------------+------------+--------------
+------------------------+----------+------------+-------------+--------------+---------------+-------------
+-----------------+----------------------+--------+-----------------------+
| % | root | *663771E441F302F025EAAFEF7B8DA65688E69556 | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y | Y |
Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | | | |
| 0 | 0 | 0 | 0 | |
|
+------+------+-------------------------------------------+-------------+-------------+-------------
+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------
+-----------------+------------+------------+--------------+------------+-----------------------
+------------------+--------------+-----------------+------------------+------------------+----------------
+---------------------+--------------------+------------------+------------+--------------
+------------------------+----------+------------+-------------+--------------+---------------+-------------
+-----------------+----------------------+--------+-----------------------+
1 row in set (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@orgorz ~]#

 

====================================

[root@orgorz ~]# ps aux|grep mysql
root 8317 0.0 0.0 57932 14016 ? S 00:20 0:00 perl /home/hmm/mysql-log/src/kk
root 19939 0.0 0.0 89400 3012 pts/9 S+ 21:28 0:00 mysql -h 10.10.253.36 -ukkdd -px
xxxxxxxxxxxxxxxxxxxxx -uroot


[root@orgorz ~]# /usr/bin/mysqladmin -uroot -p shutdown
Enter password:
/usr/bin/mysqladmin: connect to server at \'localhost\' failed
error: \'Access denied for user \'root\'@\'localhost\' (using password: YES)\'
[root@orgorz ~]# ps aux|grep mysql|grep -v grep
root 3978 0.0 0.0 66092 1340 ? S Oct21 0:00 /bin/sh /usr/bin/mysqld_safe --
datadir=/var/lib/mysql --pid-file=/var/lib/mysql/orgorz.pid
mysql 4760 3.6 1.2 2875696 1219684 ? Sl Oct21 2044:53 /usr/sbin/mysqld --basedir=/usr --
datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/orgorz.err
--open-files-limit=8192 --pid-file=/var/lib/mysql/orgorz.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root 8317 0.0 0.0 57932 14016 ? S 00:20 0:00 perl /home/hmm/mysql-log/src/kk
[root@orgorz ~]# kill -9 3978
[root@orgorz ~]# ps aux|grep mysql|grep -v grep
mysql 4760 3.6 1.2 2875696 1219684 ? Sl Oct21 2044:53 /usr/sbin/mysqld --basedir=/usr --
datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/orgorz.err
--open-files-limit=8192 --pid-file=/var/lib/mysql/orgorz.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root 8317 0.0 0.0 57932 14016 ? S 00:20 0:00 perl /home/hmm/mysql-log/src/kk
[root@orgorz ~]# kill -9 4760
[root@orgorz ~]# ps aux|grep mysql|grep -v grep
root 8317 0.0 0.0 57932 14016 ? S 00:20 0:00 perl /home/hmm/mysql-log/src/kk
[root@orgorz ~]# /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/orgorz.pid &
[1] 10834
[root@orgorz ~]# 141129 19:55:43 mysqld_safe Logging to \'/var/lib/mysql/orgorz.err\'.
141129 19:55:43 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@orgorz ~]# ps aux|grep mysql|grep -v grep
root 8317 0.0 0.0 57932 14016 ? S 00:20 0:00 perl /home/hmm/mysql-log/src/kk
root 10834 0.2 0.0 64004 1288 pts/0 S 19:55 0:00 /bin/sh /usr/bin/mysqld_safe --
datadir=/var/lib/mysql --pid-file=/var/lib/mysql/orgorz.pid
mysql 11632 33.5 0.2 2680320 238584 pts/0 Sl 19:55 0:04 /usr/sbin/mysqld --basedir=/usr --
datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/orgorz.err
--open-files-limit=8192 --pid-file=/var/lib/mysql/orgorz.pid --socket=/var/lib/mysql/mysql.sock --port=3306
[root@orgorz ~]#

 

 

[wo@orgorz ~]$ sudo su -
[root@orgorz ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 60
Server version: 5.5.14-log MySQL Community Server (GPL)

Copyright (c) 2000, 2010, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cacti |
|
| mysql |
|
+--------------------+
17 rows in set (0.11 sec)

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
mysql> update user set password=password(\'company\') where user=\'root\';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)

mysql> quit
Bye
[root@orgorz ~]# mysql
ERROR 1045 (28000): Access denied for user \'kkdd\'@\'10.10.253.36\' (using password: NO)

[root@orgorz ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user \'root\'@\'10.10.253.36\' (using password: NO)


mysql> update user set password=password("simple") where user="root";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>


[root@orgorz ~]# /usr/bin/mysqladmin -h10.10.253.36 -uroot password "simple"
/usr/bin/mysqladmin:
You cannot use \'password\' command as mysqld runs
with grant tables disabled (was started with --skip-grant-tables).
Use: "mysqladmin flush-privileges password \'*\'" instead
[root@orgorz ~]# mysqladmin flush-privileges password \'simple\'
mysqladmin: unable to change password; error: \'Can\'t find any matching row in the user table\'

[root@orgorz ~]# ps axu|grep mysql|grep -v grep
root 8317 0.0 0.0 57932 14016 ? S 00:20 0:00 perl /home/hmm/mysql-log/src/kk
[root@orgorz ~]# /usr/bin/mysqladmin -h10.10.253.36 -uroot password "simple"
/usr/bin/mysqladmin: connect to server at \'10.10.253.36\' failed
error: \'Can\'t connect to MySQL server on \'10.10.253.36\' (111)\'
Check that mysqld is running on 10.10.253.36 and that the port is 3306.
You can check this by doing \'telnet 10.10.253.36 3306\'

 

[root@orgorz ~]# /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/orgorz.pid --
skip-grant-tables &
[1] 8319
[root@orgorz ~]# 141129 20:23:56 mysqld_safe Logging to \'/var/lib/mysql/orgorz.err\'.
141129 20:23:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@orgorz ~]# ps axu|grep mysql|grep -v grep
root 8317 0.0 0.0 57932 14016 ? S 00:20 0:00 perl /home/hmm/mysql-log/src/kk
root 8319 0.2 0.0 64004 1292 pts/7 S 20:23 0:00 /bin/sh /usr/bin/mysqld_safe --
datadir=/var/lib/mysql --pid-file=/var/lib/mysql/orgorz.pid --skip-grant-tables
mysql 9128 22.0 0.2 2680320 261432 pts/7 Sl 20:23 0:01 /usr/sbin/mysqld --basedir=/usr --
datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-
error=/var/lib/mysql/orgorz.err --open-files-limit=8192 --pid-file=/var/lib/mysql/orgorz.pid --
socket=/var/lib/mysql/mysql.sock --port=3306
[root@orgorz ~]#

 

 

[root@orgorz ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.5.14-log MySQL Community Server (GPL)

Copyright (c) 2000, 2010, 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> 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
mysql>

 

UPDATE mysql.user SET Password=PASSWORD(\'mimacut\') WHERE User=\'root\';

 

 

mysql> select * from user where user=\'root\';
+-----------+------+-------------------------------------------+-------------+-------------+-------------
+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------
+-----------------+------------+------------+--------------+------------+-----------------------
+------------------+--------------+-----------------+------------------+------------------+----------------
+---------------------+--------------------+------------------+------------+--------------
+------------------------+----------+------------+-------------+--------------+---------------+-------------
+-----------------+----------------------+--------+-----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv |
Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv |
References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv
| Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv |
Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type |
ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
plugin | authentication_string |
+-----------+------+-------------------------------------------+-------------+-------------+-------------
+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------
+-----------------+------------+------------+--------------+------------+-----------------------
+------------------+--------------+-----------------+------------------+------------------+----------------
+---------------------+--------------------+------------------+------------+--------------
+------------------------+----------+------------+-------------+--------------+---------------+-------------
+-----------------+----------------------+--------+-----------------------+
| localhost | root | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | | |
| | 0 | 0 | 0 | 0 | |
|
+-----------+------+-------------------------------------------+-------------+-------------+-------------
+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------
+-----------------+------------+------------+--------------+------------+-----------------------
+------------------+--------------+-----------------+------------------+------------------+----------------
+---------------------+--------------------+------------------+------------+--------------
+------------------------+----------+------------+-------------+--------------+---------------+-------------
+-----------------+----------------------+--------+-----------------------+
1 row in set (0.01 sec)

mysql> select * from user;
+----------------+--------------+-------------------------------------------+-------------+-------------

mysql>

mysql> update user set Password="mimacut" where user=\'root\';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


mysql> select * from user where user=\'root\';
+-----------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------
+-------------+---------------+--------------+-----------+------------+-----------------+------------
+------------+--------------+------------+-----------------------+------------------+--------------
+-----------------+------------------+------------------+----------------+---------------------
+--------------------+------------------+------------+--------------+------------------------+----------
+------------+-------------+--------------+---------------+-------------+-----------------
+----------------------+--------+-----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv |
Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv |
Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv |
Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv |
Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer |
x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin |
authentication_string |
+-----------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------
+-------------+---------------+--------------+-----------+------------+-----------------+------------
+------------+--------------+------------+-----------------------+------------------+--------------
+-----------------+------------------+------------------+----------------+---------------------
+--------------------+------------------+------------+--------------+------------------------+----------
+------------+-------------+--------------+---------------+-------------+-----------------
+----------------------+--------+-----------------------+
| localhost | root | mimacut | Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y | Y
| Y | Y | Y | Y | Y | Y
| Y | Y | | | | |
0 | 0 | 0 | 0 | | |
+-----------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------
+-------------+---------------+--------------+-----------+------------+-----------------+------------
+------------+--------------+------------+-----------------------+------------------+--------------
+-----------------+------------------+------------------+----------------+---------------------
+--------------------+------------------+------------+--------------+------------------------+----------
+------------+-------------+--------------+---------------+-------------+-----------------
+----------------------+--------+-----------------------+
1 row in set (0.00 sec)

mysql>

 

 

 

 

============================================================

http://www.soso.io/article/13889.html

一、一般忘记密码的解决办法,需要重启Mysql
1、skip-grant-tables
我们常用的方法是使用skip-grant-tables选项,mysqld server启动之后并不使用权限系统(privilege system)。用户不需要任何账号、不受任何限制的访问数据库中所有数据。为了安全起见,通常加上 skip-networking ,mysqld不侦听任何TCP/IP连接请求。操作过程如下,
1)修改my.cnf配置文件,在mysqld选项中添加skip-grant-tables和skip-networking。
2)再重启mysqld server。
3)通过sql语句修改mysql.user表中存储密码。执行flush privileges,重新启用mysql权限系统。

代码如下:
UPDATE mysql.USER SET Password=PASSWORD(\'newpwd\')WHERE User=\'root\'; 
FLUSH PRIVILEGES;


4)删除或者注释配置文件中skip-grant-tables和skip-networking的参数选项。如果使用skip-networking,则需要再次重启mysqld。因为skip-networking不是系统变量,只是mysqld的参数选项,而不能通过系统变量动态进行设置。如果没有适用skip-networking,只需要执行flush privileges就可以使权限系统重新生效。 
2. --init-file 
mysqld_safe可以使�init-file参数选项来执行重新设定密码的sql语句。 
1)新建一个初始化文件,如/tmp/initfile,文件内容为上面修改密码的sql语句。 

代码如下:
UPDATE mysql.user SET Password=PASSWORD(\'newpwd\') WHERE User=\'root\'; 
FLUSH PRIVILEGES;


2)关闭mysqld服务进程。 
3)使用mysqld_safe启动mysqld; 

代码如下:
mysqld_safe --init-file=/home/me/mysql-init &


上面的两种方法是在忘记root密码情况下重新设置密码的方法,可以发现都需要重启mysqld服务。很多人都是使用第一种进行重置root密码,但是比较推荐的做法反而是第二种,即安全有快捷简单。

 

二、不重启mysqld的方法

1、首先得有一个可以拥有修改权限的mysql数据库账号,当前的mysql实例账号(较低权限的账号,比如可以修改test数据库)或者其他相同版本实例的账号。把data/mysql目录下面的user表相关的文件复制到data/test目录下面。

代码如下:

[root@localhost mysql]# cp mysql/user.* test/ 
[root@localhost mysql]# chown mysql.mysql test/user.*


2、使用另一个较低权限的账号链接数据库,设置test数据库中的user存储的密码数据。 

代码如下:

[root@localhost mysql]# mysql -utest -p12345 
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 17 
Server version: 5.5.25a-log Source distribution

 

Copyright (c) 2000, 2011, 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> use test
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
mysql> update user set password=password(\'yayun\') where user=\'root\';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5  Changed: 0  Warnings: 0

mysql>


3、把修改后的user.MYD和user.MYI复制到mysql目录下,记得备份之前的文件。 

代码如下:

mv mysql/user.MYD mysql/user.MYD.bak 
mv mysql/user.MYI mysql/user.MYI.bak 
cp test/user.MY* mysql/ 
chown mysql.mysql mysql/user.*


4、查找mysql进程号,并且发送SIGHUP信号,重新加载权限表。 

代码如下:

[root@localhost mysql]# pgrep -n mysql 
2184 
[root@localhost mysql]# 
[root@localhost mysql]# kill -SIGHUP 2184


5、登陆测试 

代码如下:

[root@localhost mysql]# mysql -uroot -pyayun 
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 20 
Server version: 5.5.25a-log Source distribution

 

Copyright (c) 2000, 2011, 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>

 

 http://www.doudouxitong.com/guzhang/linux/2014/0614/1952.html

 登陆网站、电子邮箱或银行卡取款等等我们都需要输入密码。MySQL软件采用了双授权政策(本词条“授权政策”),它分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择MySQL作为网站数据库。所以MySQL软件也被广泛使用,有时候难免会忘记密码,下面来介绍下linux mysql root密码重置方法。

  linux mysql root密码重置方法一:

  1. 停止mysql服务 /etc/init.d/mysql stop

  2. 在终端输入 /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=root 此时mysql以跳过检测的模式运行

  3. 打开另一个终端

  输入 mysql -uroot 进入mysql ,

  mysql> update mysql.user set Password=PASSWORD(\'密码\') where user = \'root\';

  mysql> FLUSH PRIVILEGES;

  4. 退出mysql

  5. 启动mysql服务 /etc/init.d/mysql start

  MySQL密码的恢复方法二:

  有可能你的系统没有 safe_mysqld 程序(ubuntu操作系统, apt-get安装的mysql) , 下面方法可以恢复

  1.切换到root下

  su root

  2. 停止mysqld;

  /etc/init.d/mysql stop

  3. 用以下命令启动MySQL,以不检查权限的方式启动;

  mysqld --skip-grant-tables &

  4. 然后用空密码方式使用root用户登录 MySQL;

  mysql -u root

  4. 修改root用户的密码为123456(当然,你需要将123456改成你要设置的密码);

  mysql> update mysql.user set password=PASSWORD(\'123456\') where User=\'root\';

  mysql> flush privileges;

  mysql> quit

  重新启动MySQL

  /etc/init.d/mysql restart

  就可以使用新密码 123456 登录了。

 

 

http://database.51cto.com/art/201005/202227.htm

以下的文章主要讲述的是MySQL root密码忘记的实际解决方法,MySQL root密码在实际应用中是经常被用到的,如果不小心将root密码弄丢的话,你就可以通过我们的文章对MySQL root密码恢复有一个更好的了解。

MySQL root密码的恢复方法之一

 

如果忘记了MySQL root密码,可以用以下方法重新设置:

 

1. KILL掉系统里的MySQL进程;

 

 

  1. killall -TERM MySQLd  

 

2. 用以下命令启动MySQL,以不检查权限的方式启动;

 

 

  1. safe_MySQLd --skip-grant-tables &  

 

3. 然后用空密码方式使用root用户登录 MySQL;

 

 

  1. MySQL -u root  

 

4. 修改root用户的密码;

 

 

  1. MySQL> update MySQL.user set password=PASSWORD(\'新密码\') where User=\'root\';   
  2. MySQL> flush privileges;   
  3. MySQL> quit  

 

 

重新启动MySQL,就可以使用新密码登录了。

 

MySQLroot密码的恢复方法二

 

有可能你的系统没有 safe_MySQLd 程序(比如我现在用的 ubuntu操作系统, apt-get安装的MySQL) , 下面方法可以恢复

 

1. 停止MySQLd;

 

 

  1. sudo /etc/init.d/MySQL stop 

 

(您可能有其它的方法,总之停止MySQLd的运行就可以了)

 

2. 用以下命令启动MySQL,以不检查权限的方式启动;

 

 

  1. MySQLd --skip-grant-tables & 

 

3. 然后用空密码方式使用root用户登录 MySQL;

 

 

  1. MySQL -u root 

 

4. 修改root用户的密码;

 

 

  1. MySQL> update MySQL.user set password=PASSWORD(\'newpassword\') where User=\'root\';   
  2. MySQL> flush privileges;   
  3. MySQL> quit  

 

 

重新启动MySQL

 

 

  1. /etc/init.d/MySQL restart 

 

就可以使用新密码 newpassword 登录了。

 

以上的相关内容就是对MySQL root密码忘记的解决 的介绍,望你能有所收获。

 

http://www.ft-love.com/mysql-reset-root-password-way.html

Linux下忘记mysql之root密码的恢复方法

只要我们的数据库表建好以后,基本上mysql就不去动它了,正因为mysql太久不用,有时会忘记密码,但别担心,还是有方法可以恢复或修改的。</p>

操作方法:

首先要停止运行的mysql

使用的命令:

#service mysqld stop
1.

或:

#rcmysqld stop
1.

或:

#kill -TERM mysqld
1.

然后用以下命令方式启动

#/www/wdlinux/mysql/bin/mysqld_safe --skip-grant-tables &
1.

说明:"--skip-grant-tables" 这是mysql的启动参数,通常这个参数在忘记mysql之root密码时使用,其意义是启动mysql时不启动grant-tables(授权表)。

然后进入mysql终端

#/www/wdlinux/mysql/bin/mysql -uroot -p
1.

此时的mysql没有密码,直接回车即可进入mysql.

然后执行选库操作

mysql> use mysql;
1.

然后执行更新mysql库密码操作

mysql> update user set password=password("你要设置的密码") where user="root";
1.

然后执行刷新MySQL的系统权限相关表密码操作并退出

注意:如果不刷新的话,会出现拒绝访问.

mysql>flush privileges;
mysql>exit
1.
2.

最后为了使新设置生效,建议用普通的方式启动mysqld

service mysqld start
1.

ok,所有的工作完成了。

 

 

http://pvbutler.blog.51cto.com/7662323/1354088

如何设置Mysql密码?

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[root@justin ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we\'ll need the current
password for the root user.  If you\'ve just installed MySQL, and
you haven\'t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y    --设置root密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y    --移除匿名用户
 ... Success!
Normally, root should only be allowed to connect from \'localhost\'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y  --不允许远程通过root登陆
 ... Success!
By default, MySQL comes with a database named \'test\' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y  --移除测试数据库
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y    --重新加载特权表
 ... Success!
Cleaning up...
All done!  If you\'ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@justin ~]#

 

怎么修改数据库密码?

 

1
2
3
[root@justin ~]# mysqladmin -u root -p password "justin"
Enter password:
[root@justin ~]#

"justin"为需要修改为的密码,Enter password后输入的是原来的密码

    遗忘数据库密码?

a、修改MySQL配置文件,在[mysqld]下任意位置添加一行“skip-grant-tables”并重启mysql服务

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@justin ~]# cp /etc/my.cnf /etc/my.cnfbak
[root@justin ~]# vim /etc/my.cnf
25 # The MySQL server
26 [mysqld]
27 port            = 3306
28 socket          = /var/lib/mysql/mysql.sock
29 skip-grant-tables
30 skip-locking
31 key_buffer_size = 16M
[root@justin ~]# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@justin ~]#

      b、登陆mysql修改root密码

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@justin ~]# mysql -uroot -p
Enter password:   --直接回车
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection idis 2
Server version: 5.1.71-log Source distribution
Copyright (c) 2000, 2013, Oracle and/oritsaffiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/orits
affiliates. Other names may be trademarks of their respective
owners.
Type \'help;\'or \'\h\'forhelp. Type \'\c\'to clearthe current input statement.
mysql> use mysql;   --使用mysql数据库
Database changed
mysql> update user setpassword=password("newpassword") where user="root";   --newpassword为新的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.01 sec)
mysql> quit
Bye
[root@justin ~]#

 c、取消刚才在/etc/my.cnf中添加的skip-grant-tables并重启服务后使用newpassword成功登陆mysql

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@justin ~]# vim /etc/my.cnf
26 [mysqld]
27 port            = 3306
28 socket          = /var/lib/mysql/mysql.sock
29 #kip-grant-tables
30 skip-locking
[root@justin ~]# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@justin ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection idis 2
Server version: 5.1.71-log Source distribution
Copyright (c) 2000, 2013, Oracle and/oritsaffiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/orits
affiliates. Other names may be trademarks of their respective
owners.
Type \'help;\'or \'\h\'forhelp. Type \'\c\'to clearthe current input statement.
mysql>
 

 

 

 

http://blog.chinaunix.net/uid-29063464-id-4079012.html

一.MySQL密码的恢复方法之一 
如果忘记了MySQL的root密码,可以用以下方法重新设置:
1.切换到root下
su root 
2. KILL掉系统里的MySQL进程; 
killall -TERM mysqld 
3. 用以下命令启动MySQL,以不检查权限的方式启动; 
safe_mysqld --skip-grant-tables & 
4. 然后用空密码方式使用root用户登录 MySQL; 
mysql -u root 
5. 修改root用户的密码; 

点击(此处)折叠或打开

  1. mysql> update mysql.user set password=PASSWORD(\'123456\') where User=\'root\'; 
  2. mysql> flush privileges; 
  3. mysql> quit

重新启动MySQL,就可以使用新密码登录了。 
二. MySQL密码的恢复方法二
有可能你的系统没有 safe_mysqld 程序(ubuntu操作系统, apt-get安装的mysql) , 下面方法可以恢复
1.切换到root下
su root
2. 停止mysqld; 
   /etc/init.d/mysql stop
3. 用以下命令启动MySQL,以不检查权限的方式启动; 
mysqld --skip-grant-tables &
4. 然后用空密码方式使用root用户登录 MySQL; 
mysql -u root
4. 修改root用户的密码为123456(当然,你需要将123456改成你要设置的密码); 

点击(此处)折叠或打开

  1. mysql> update mysql.user set password=PASSWORD(\'123456\') where User=\'root\'; 
  2. mysql> flush privileges; 
  3. mysql> quit

重新启动MySQL
/etc/init.d/mysql restart
就可以使用新密码 123456 登录了。 
三.MYSQL密码的恢复方法三:
1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库。
因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的
状态下,其他的用户也可以任意地登录和修改MySQL的信息。可以采用将MySQL对
外的端口封闭,并且停止Apache以及所有的用户进程的方法实现服务器的准安全
状态。最安全的状态是到服务器的Console上面操作,并且拔掉网线。
2.修改MySQL的登录设置:
# vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:

点击(此处)折叠或打开

  1. [mysqld]
  2. datadir=/var/lib/mysql
  3. socket=/var/lib/mysql/mysql.sock
  4. skip-grant-tables

保存并且退出vi。
3.重新启动mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
4.登录并修改MySQL的root密码

点击(此处)折叠或打开

  1. # /usr/bin/mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 3 to server version: 3.23.56
  4. Type \'help;\' or \'\h\' for help. Type \'\c\' to clear the buffer.
  5. mysql> USE mysql ;
  6. Reading table information for completion of table and column names
  7. You can turn off this feature to get a quicker startup with -A
  8. Database changed
  9. mysql> UPDATE user SET Password = password ( \'new-password\' ) WHERE User = \'root\' ;
  10. Query OK, 0 rows affected (0.00 sec)
  11. Rows matched: 2 Changed: 0 Warnings: 0
  12. mysql> flush privileges ;
  13. Query OK, 0 rows affected (0.01 sec)
  14. mysql> quit
  15. Bye


5.将MySQL的登录设置修改回来
# vi /etc/my.cnf
将刚才在[mysqld]的段中加上的skip-grant-tables删除
保存并且退出vi。
6.重新启动mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

分类:

技术点:

相关文章: