GRANT
и REVOKE
Buy this Reference Manual in softcover from Barnes & Noble!
В большинстве случаев для задания пользователей и их паролей следует пользоваться командой GRANT
, поэтому приведенная ниже информация предназначена для опытных пользователей. See section 4.3.1 Синтаксис команд GRANT
и REVOKE
.
В примерах, приведенных в предыдущих разделах, демонстрируется важный принцип, который заключается в следующем: при сохранении непустых паролей с использованием операторов INSERT
или UPDATE
для их шифрования должна применяться функция PASSWORD()
. Это делается потому, что в таблице user
пароли хранятся в зашифрованном виде, а не как простой текст. Предположим, что мы упустили это из виду и задали пароли следующим образом:
shell> mysql -u root mysql mysql> INSERT INTO user (Host,User,Password) -> VALUES('%','jeffrey','biscuit'); mysql> FLUSH PRIVILEGES;
В результате выполнения этих команд в таблице user будет сохранено значение пароля biscuit
в виде простого текста. Когда пользователь jeffrey
попытается подсоединиться к серверу, используя этот пароль, клиент mysql
зашифрует его при помощи функции PASSWORD()
, сгенерирует вектор аутентификации, основанный на зашифрованном пароле и случайно выбранном числе, полученном от сервера, и направит результат на сервер. Сервер использует значение password
из таблицы user
(в данном случае, это незашифрованное значение biscuit
), чтобы осуществить точно такие же вычисления, и сравнит результаты. Результаты не совпадут, и сервер не позволит установить соединение:
shell> mysql -u jeffrey -pbiscuit test Access denied
Перед занесением в таблицу user
пароли необходимо зашифровывать, поэтому оператор INSERT
должен использоваться следующим образом:
mysql> INSERT INTO user (Host,User,Password) -> VALUES('%','jeffrey',PASSWORD('biscuit'));
При использовании оператора SET PASSWORD
также необходимо применять функцию PASSWORD()
:
mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');
Если пароль задается при помощи оператора GRANT ... IDENTIFIED BY
или команды mysqladmin password
, нет необходимости использовать функцию PASSWORD()
. Обе эти команды самостоятельно производят шифровку пароля, поэтому пароль следует указывать как biscuit
, например, таким образом:
mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
или
shell> mysqladmin -u jeffrey password biscuit
Примечание: Функция PASSWORD()
шифрует пароли отличным от Unix образом. Не следует полагать, что если ваши пароли для Unix и для MySQL совпадают, то функция PASSWORD()
выдаст точно такой же результат шифрования, как и файл паролей Unix. See section 4.3.2 Имена пользователей MySQL и пароли.
Posted by [name withheld] on Friday October 25 2002, @7:21am | [Delete] [Edit] |
Listen up kids, 'cause this doesn't seem to be
anywhere in the documentation and it's really
important to know if you're planning on matching
plaintext strings against password() encrypted fields
in your tables: Apparently password() creates a
garbled alpha-numeric string that is ALWAYS 16
CHARACTERS LONG. If your field is less than 16
characters long, the string will get truncated and
you'll be out in the wind when the time comes to
compare your plaintext candidates. I can't tell you
how long it took me to figure this out, so I hope this
note saves someone else the agrivation I went
through to end up writing it. Additionally, if someone
from mySQL is reading this, you might want to add
this fact to the manual officially. It seems to me like
a pretty vital scrap of information to omit.
Posted by Dee Kintaudi on Thursday November 21 2002, @12:24pm | [Delete] [Edit] |
Okay I got a question and a problem with Mysql and
passwords:). I tried to use several of the options
and most of them have not worked.
However one soloution did work and I tested it out
twice and it was solid. Of course I lost the little piece
of paper I wrote it out on and I can't seem to find
this soloution anywhere, as if it did not exist or
maybe I imagined it.
The soloution that worked for me, before I lost the
little slip of paper I wrote it down on goes something
like this.....
Insert into user root
Password "my password"
and then something with 'Y', 'Y', 'Y', (about a dozen
or 15 times or so)
However, I can not find this soloution anywhere can
someone help me out here?
Posted by [name withheld] on Tuesday February 18 2003, @5:01pm | [Delete] [Edit] |
here's what it should look like.
write your update statement accordingly.
mysql> select * from user \G
*************************** 1. row ***************************
Host: localhost
User: root
Password:
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
*************************** 2. row ***************************
Host: localhost.localdomain
User: root
Password:
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
*************************** 3. row ***************************
Host: localhost
User:
Password:
Select_priv: N
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Reload_priv: N
Shutdown_priv: N
Process_priv: N
File_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
*************************** 4. row ***************************
Host: localhost.localdomain
User:
Password:
Select_priv: N
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Reload_priv: N
Shutdown_priv: N
Process_priv: N
File_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Posted by Rich Young on Monday March 3 2003, @10:11pm | [Delete] [Edit] |
Here's a time-saver: If you're hand-editing these tables, don't forget to run "FLUSH PRIVILEGES;" afterwards, or your changes won't actually take effect.
Add your own comment.