Securing the Initial MySQL Accounts
141
shell>
mysqladmin -u root -p shutdown
Enter password:
(enter root password here)
Assigning Anonymous Account Passwords
The
mysql
commands in the following instructions include a
-p
option based on the assumption that
you have set the
root
account passwords using the preceding instructions and must specify that
password when connecting to the server.
To assign passwords to the anonymous accounts, connect to the server as
root
, then use either
SET
PASSWORD
or
UPDATE
. Be sure to encrypt the password using the
PASSWORD()
[956]
function.
To use
SET PASSWORD
on Windows, do this:
shell>
mysql -u root -p
Enter password:
(enter root password here)
mysql>
SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');
To use
SET PASSWORD
on Unix, do this:
shell>
mysql -u root -p
Enter password:
(enter root password here)
mysql>
SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');
mysql>
SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');
To set the anonymous-user account passwords with a single
UPDATE
statement, do this (on any
platform):
shell>
mysql -u root -p
Enter password:
(enter root password here)
mysql>
UPDATE mysql.user SET Password = PASSWORD('newpwd')
->
WHERE User = '';
mysql>
FLUSH PRIVILEGES;
The
FLUSH
statement causes the server to reread the grant tables. Without it, the password change
remains unnoticed by the server until you restart it.
Removing Anonymous Accounts
If you prefer to remove any anonymous accounts rather than assigning them passwords, do so as
follows on Windows:
shell>
mysql -u root -p
Enter password:
(enter root password here)
mysql>
DROP USER ''@'localhost';
On Unix, remove the anonymous accounts like this:
shell>
mysql -u root -p
Enter password:
(enter root password here)
mysql>
DROP USER ''@'localhost';
mysql>
DROP USER ''@'host_name';
Securing Test Databases
By default, the
mysql.db
table contains rows that permit access by any user to the
test
database
and other databases with names that start with
test_
. (These rows have an empty
User
column
value, which for access-checking purposes matches any user name.) This means that such databases
can be used even by accounts that otherwise possess no privileges. If you want to remove any-user
access to test databases, do so as follows:
shell>
mysql -u root -p
Enter password:
(enter root password here)
mysql>
DELETE FROM mysql.db WHERE Db LIKE 'test%';
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...