不用密码进入数据库

# service mysqld stop
Shutting down MySQL. SUCCESS! 

 

# mysqld_safe --skip-grant-tables &

 

[root@centos01 server]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.20-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> 

 无需密码进入mysql数据库

 

如果不成功的话:

[root@centos02 bin]# vi /etc/my.cnf
[mysqld]
skip-grant-tables #加上这句话

 

[root@centos02 bin]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 

[root@centos02 bin]# ls
innochecksum       mysql_client_test_embedded  mysql_secure_installation
msql2mysql         mysql_config                mysql_setpermission
myisamchk          mysql_convert_table_format  mysqlshow
myisam_ftdump      mysqld                      mysqlslap
myisamlog          mysqld-debug                mysqltest
myisampack         mysqld_multi                mysqltest_embedded
my_print_defaults  mysqld_safe                 mysql_tzinfo_to_sql
mysql              mysqldump                   mysql_upgrade
mysqlaccess        mysqldumpslow               mysql_waitpid
mysqlaccess.conf   mysql_embedded              mysql_zap
mysqladmin         mysql_find_rows             perror
mysqlbinlog        mysql_fix_extensions        replace
mysqlbug           mysqlhotcopy                resolveip
mysqlcheck         mysqlimport                 resolve_stack_dump
mysql_client_test  mysql_plugin
[root@centos02 bin]# ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.40-log MySQL Community Server (GPL)

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.

mysql> 

 

mysql> update user set password = password('123') where user = 'root';#这样不行,必须清空密码!!
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)

 

 

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

 

[root@centos02 bin]# vi /etc/my.cnf #将刚才在[mysqld]的段中加上的skip-grant-tables删除 
[root@centos02 bin]# service mysqld restart
Shutting down MySQL. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@centos02 bin]# ./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.40-log MySQL Community Server (GPL)

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.

mysql> 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

[root@DB bin]# /etc/init.d/mysqld stop
Shutting down MySQL. SUCCESS! 
[root@DB bin]# mysqld_safe --skip-grant-tables &
[root@DB bin]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.40-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.

mysql>  

 

mysql> select user,host,password from user;
+--------+-----------+-------------------------------------------+
| user   | host      | password                                  |
+--------+-----------+-------------------------------------------+
| root   | 127.0.0.1 |                                           |
| zabbix | %         | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+--------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)
mysql> update user set host="localhost" where user="root";
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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

mysql> select user,host,password from user;
+--------+-----------+-------------------------------------------+
| user   | host      | password                                  |
+--------+-----------+-------------------------------------------+
| root   | localhost |                                           |
| zabbix | %         | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+--------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)

mysql> 

 

[root@DB bin]# service mysqld status
 SUCCESS! MySQL running (2730)
[root@DB bin]# /etc/init.d/mysqld stop
Shutting down MySQL.160612 18:46:19 mysqld_safe mysqld from pid file /usr/local/mysql/data/DB.pid ended
 SUCCESS! 
[1]+  Done                    mysqld_safe --skip-grant-tables
[root@DB bin]# service mysqld start
Starting MySQL.. SUCCESS! 
[root@DB bin]# 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.40-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.

mysql> 

 

mysql> use mysql
Database changed
mysql> update user set password=('') where user='root';#应该是update user set password=password("newpassword") 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.01 sec)

mysql> select user,host,password from user;
+------+-----------+----------+
| user | host      | password |
+------+-----------+----------+
| root | localhost |          |
+------+-----------+----------+
1 row in set (0.00 sec)
#注释掉/etc/my.cnf 中的skiip-grant-tables后重启服务器 并重新设置密码,新密码有效!
mysql> update user set password=("3006") where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> select user,host,password from user;
+------+-----------+----------+
| user | host      | password |
+------+-----------+----------+
| root | localhost | 3006     |#这种情况不对(即可见,最重要的是不能用!)
+------+-----------+----------+
1 row in set (0.00 sec)

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

 

 

[root@DB-S ~]# mysqladmin -uroot password
New password: 
Confirm new password: 
mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *5E9021B1C46435835981A94A7087707B3465144B |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值