当前位置:Gxlcms > 数据库问题 > MySQL权限

MySQL权限

时间:2021-07-01 10:21:17 帮助过:18人阅读

查看当前用户的权限:
mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘localhost‘ WITH GRANT OPTION |
| GRANT PROXY ON ‘‘@‘‘ TO ‘root‘@‘localhost‘ WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

查看某个用户的权限:
mysql> show grants for ‘jack‘@‘%‘;
+-----------------------------------------------------------------------------------------------------+
| Grants for jack@%                                                                                   |
+-----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘jack‘@‘%‘ IDENTIFIED BY PASSWORD ‘*9BCDC990E611B8D852EFAF1E3919AB6AC8C8A9F0‘ |
+-----------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
技术分享

    4、回收权限

mysql> revoke delete on *.* from ‘jack‘@‘localhost‘;
Query OK, 0 rows affected (0.01 sec)

    5、删除用户

技术分享
mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root |                                           |
| rhel5.4   | root |                                           |
| 127.0.0.1 | root |                                           |
| ::1       | root |                                           |
| localhost |      |                                           |
| rhel5.4   |      |                                           |
| localhost | jack | *9BCDC990E611B8D852EFAF1E3919AB6AC8C8A9F0 |
+-----------+------+-------------------------------------------+
7 rows in set (0.00 sec)

mysql> drop user ‘jack‘@‘localhost‘;
Query OK, 0 rows affected (0.01 sec)
技术分享

    6、对账户重命名

mysql> rename user ‘jack‘@‘%‘ to ‘jim‘@‘%‘;
Query OK, 0 rows affected (0.00 sec)

    7、修改密码

技术分享
  1、用set password命令
mysql> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘123456‘);
Query OK, 0 rows affected (0.00 sec)
  2、用mysqladmin
  [root@rhel5 ~]# mysqladmin -uroot -p123456 password 1234abcd
  备注:
  格式:mysqladmin -u用户名 -p旧密码 password 新密码
  3、用update直接编辑user表
  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(‘1234abcd‘) 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.00 sec)
  4、在丢失root密码的时候:
  [root@rhel5 ~]# mysqld_safe --skip-grant-tables &
[1] 15953
[root@rhel5 ~]# 130911 09:35:33 mysqld_safe Logging to ‘/mysql/mysql5.5/data/rhel5.4.err‘.
130911 09:35:33 mysqld_safe Starting mysqld daemon with databases from /mysql/mysql5.5/data

[root@rhel5 ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.22 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> \s
--------------
mysql  Ver 14.14 Distrib 5.5.22, for Linux (i686) using  EditLine wrapper

Connection id:        2
Current database:    
Current user:        root@
SSL:            Not in use
Current pager:        stdout
Using outfile:        ‘‘
Using delimiter:    ;
Server version:        5.5.22 Source distribution
Protocol version:    10
Connection:        Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /tmp/mysql.sock
Uptime:            36 sec

Threads: 1  Questions: 5  Slow queries: 0  Opens: 23  Flush tables: 1  Open tables: 18  Queries per second avg: 0.138
--------------

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(‘123456‘) 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权限

标签:oca   process   机器   安全   line   root密码   删除数据库   ssl   match   

人气教程排行