mysql的用户管理(四)

来源:互联网 发布:php a href on click 编辑:程序博客网 时间:2024/05/22 03:40

修改用户的密码:

 

默认情况下, 客户端连接到数据对资源的使用是没有限制的,mysql有四种方法控制客户端连接到服务器的资源:

  | MAX_QUERIES_PER_HOUR count  :每小时可以查询的次数
  | MAX_UPDATES_PER_HOUR count : 每小时可以update的次数
  | MAX_CONNECTIONS_PER_HOUR count :每小时最多的连接次数
  | MAX_USER_CONNECTIONS count    :并发连接最大次数

如果一个帐没有密码并且有数据的full privilegs权限是非常危险的,任何人任何地方只要知道这台数据库的IP地址都能连接过来。

为了防止这样的事发生,可以在没有密码的数据库上,在启动的时候加一-skip-networking选项,这样就会阻止从TCP/IP的所有连接,也就是只能本地连接了。

 

另外如果root的密码忘记了怎么连接到数据库呢?

这时可以关闭数据库,在重启时加上skip-grant-tables的选项,mysql在开启时就不会装载系统权限,这样就可以不用密码登入了。

不过之后要记得重置root密码,正常的重启数据库。

下面做一个验示:

mysql> set password for 'root'@'localhost'=password('root');
Query OK, 0 rows affected (0.03 sec)

mysql> exit
Bye

此时如果我忘记密码,直接键入mysql是登不进去的
[root@rhel131 data]# mysql
ERROR 1045 (28000): Access denied for user
'root'@'localhost' (using password: NO)

关闭mysql,重启时加上--skip-grant-tables参数,就可以直接进入了

[root@rhel131 data]# service mysql stop
Shutting down MySQL..                                      [  OK  ]
[root@rhel131 data]# mysqld_safe --skip-grant-tables &
[1] 12548
[root@rhel131 data]# 131106 20:29:38 mysqld_safe Logging to '/usr/local/mysql/data/rhel131.err'.
131106 20:29:38 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@rhel131 data]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.13 Source distribution

Copyright (c) 2000, 2013, 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
mysql> update user set password='' where user='root' and host='localhost';

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)

 

 

原创粉丝点击