备注:可以使用GRANT重复给用户添加权限,权限叠加,比如你先给用户添加了一个select权限,然后又给用户添加了一个insert权限,那么该用户就同时拥有了select和insert权限。
以下都在我的是实验机上操作!
mysql> GRANT USAGE,SELECT ON *.* TO public@'我的本机IP地址' IDENTIFIED BY 'pbpass' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec)在我的试验机使用以下命令可以查看用户表:
select Host,User,Password from mysql.user;确定添加正确后我可以在本机远程登陆试验机啦?
以下在本机操作!
我们再次尝试远程连接我的试验机数据库,使用我们在试验机上添加的访问账号去连接!
mysql -u public -h 我的试验机IP地址 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.15-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)
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> 成功登陆我的实验室数据库,接下来的操作取决于你的权限,例如我创建的public账号只有访问权限,则这个账号就不能创建删除了!
我们查看下我的试验机有哪些用户:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | test | | world | +--------------------+ 7 rows in set (0.00 sec) mysql> select Host,User,Password from mysql.user; +-----------------+--------+-------------------------------------------+ | Host | User | Password | +-----------------+--------+-------------------------------------------+ | localhost | root | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | | 127.0.0.1 | root | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | | ::1 | root | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | | 本机IP地址 | public | *5067452449A119B7FA902EEDF47385AF750C6297 | +-----------------+--------+-------------------------------------------+ 5 rows in set (0.00 sec) mysql>如果你也是pbpass这个密码,你会发现共同点。So,安全很重要,数据库用户权限很重要,这提醒我们,mysql这样的特殊表,不要给其他任何人看到!
安全为本,So,删除哪些不需要的用户吧,等以后需要再添加不迟!
删除用户
注意删除用户不要使用DELETE直接删除,因为使用DELETE删除后用户的权限并未删除,新建同名用户后又会继承以前的权限。正确的做法是使用DROP USER命令删除用户!
drop user 'public'@我的本机IP地址; Query OK, 0 rows affected (0.00 sec)表示成功,可以再次查看。
更新用户密码
其他的用户要不设置密码,要不删除。怎么设置密码呢?
方法一:mysqladmin
开头已经说了一种方法,即使用以下命令:
mysqladmin -u root -p[oldpass] password newpass
方法二:使用表更新命令
mysql> UPDATE mysql.user SET Password=PASSWORD('新密码') WHERE User='root' and Host='127.0.0.1';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1? Changed: 1? Warnings: 0
mysql> FLUSH PRIVILEGES; 需要注意一定要使用PASSWORD()函数!要不什么后果自己想。
方法三:set password
mysql> set password for 'root'@'::1'=PASSWORD('新密码');
Query OK, 0 rows affected (0.00 sec)
mysql>
备注:更新完毕使用FLUSH PRIVILEGES;命令刷新权限,否则还是原来的密码!?
本文由@The_Third_Wave(Blog地址:http://blog.csdn.net/zhanh1218)原创。还有未涉及的,会不定期更新,有错误请指正。
如果你看到这篇博文时发现没有不完整,那是我为防止爬虫先发布一半的原因,请看原作者Blog。
如果这篇博文对您有帮助,为了好的网络环境,不建议转载,建议收藏!如果您一定要转载,请带上后缀和本文地址。