MySQL之账号管理
一 账号管理
创新互联公司是一家集网站建设,龙马潭企业网站建设,龙马潭品牌网站建设,网站定制,龙马潭网站建设报价,网络营销,网络优化,龙马潭网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
1 创建账号:
示例 1:
建立账号zwj,权限为在所有数据库上具有所有权限
MySQL> grant all on *.* to 'zwj'@'192.168.154.180';
Query OK, 0 rows affected (0.01 sec)
为zwj设置密码
mysql> grant all on *.* to 'zwj'@'192.168.154.180' identified by 'zwj';
Query OK, 0 rows affected (0.00 sec)
示例 2:
建立用户user01,权限为test库里所有表进行select、update、insert、delete操作,密码为"a123"。
mysql> grant select,update,insert,delete on test.* to 'user01'@'192.168.154.%' identified by 'a123';
Query OK, 0 rows affected (0.09 sec)
2 查看权限
查看指定账户的权限
mysql> show grants for 'user01'@'192.168.154.%';
+-------------------------------------------------------------------------------------------------------------------+
| Grants for user01@192.168.154.% |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'user01'@'192.168.154.%' IDENTIFIED BY PASSWORD '*FF680E568727C9C00FABFEE03D13BA727047CC65' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'user01'@'192.168.154.%' |
+-------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
查看当前用户权限
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*DCB7DF5FFC82C441503300FFF165257BC551A598' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
3 更改权限
新建用户
mysql> grant select on test.* to 'bbs'@'192.168.154.%' identified by 'bbs';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'bbs'@'192.168.154.%';
+----------------------------------------------------------------------------------------------------------------+
| Grants for bbs@192.168.154.% |
+----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'bbs'@'192.168.154.%' IDENTIFIED BY PASSWORD '*74BAEAC2CAFC5C7162EF373C5C85EFBC7FC8B803' |
| GRANT SELECT ON `test`.* TO 'bbs'@'192.168.154.%' |
+----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
增加权限
mysql> grant select,insert,delete on test.* to 'bbs'@'192.168.154.%';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'bbs'@'192.168.154.%';
+----------------------------------------------------------------------------------------------------------------+
| Grants for bbs@192.168.154.% |
+----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'bbs'@'192.168.154.%' IDENTIFIED BY PASSWORD '*74BAEAC2CAFC5C7162EF373C5C85EFBC7FC8B803' |
| GRANT SELECT, INSERT, DELETE ON `test`.* TO 'bbs'@'192.168.154.%' |
+----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
撤销权限
mysql> revoke delete,insert on test.* from 'bbs'@'192.168.154.%';
Query OK, 0 rows affected (0.01 sec)
mysql> show grants for 'bbs'@'192.168.154.%';
+----------------------------------------------------------------------------------------------------------------+
| Grants for bbs@192.168.154.% |
+----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'bbs'@'192.168.154.%' IDENTIFIED BY PASSWORD '*74BAEAC2CAFC5C7162EF373C5C85EFBC7FC8B803' |
| GRANT SELECT ON `test`.* TO 'bbs'@'192.168.154.%' |
+----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
4 修改账号密码
方式 1:
mysql> set password for 'bbs'@'192.168.154.%' = password('abc-123');
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
方式 2:
mysql> update mysql.user set password=password('aaa') where user='bbs' and host='192.168.154.%';
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)
方式 3:
[root@localhost tmp]# mysqladmin -u bbs -h 192.168.154.180 password "ccc" -p
Enter password:
Warning: Using a password on the command line interface can be insecure.
为root初次设置密码:
[root@www ~]# mysqladmin -uroot password "abc-123"
为root修改密码:
[root@localhost tmp]# mysqladmin -uroot password 'root' -p
Enter password:
Warning: Using a password on the command line interface can be insecure.
5 删除账户
mysql> drop user 'bbs'@'192.168.154.%';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'bbs'@'192.168.154.%';
ERROR 1141 (42000): There is no such grant defined for user 'bbs' on host '192.168.154.%'
网站栏目:MySQL之账号管理
文章起源:http://hbruida.cn/article/gidgeo.html