The root account passwords can be set several ways. The following
discussion demonstrates three
methods:
• Use the set password statement
• Use the UPDATE statement
• Use the mysąladmin command-line Client program
To assign passwords using set password, connect to the server as root and issue a set
PASSWORD statement for each root account listed in the mysąl .user
table. Be surę to encrypt the
password using the password () [1283] function.
For Windows, do this:
shell>raysql -u root
mysql>SET PASSWORD FOR 'root'0'localhost• = PASSWORD ('ne*pwd') ; mysql>SET PASSWORD FOR ' root' 0 • 127.0.0.1 • = PASSWORD (' newpurd') ; mysql>SET PASSWORD FOR ’root'@’::1• = PASSWORD('newpwd’); mysql>SET PASSWORD FOR 1root' 0 ' % ' = PASSWORD('newpwd');
The last statement is unnecessary if the mysąl .user table has no root account with a host value of
For Unix, do this:
Shell>icysql -u root
mysql>SET PASSWORD FOR ’root'0'localhost' = PASSWORD ('newpwd') ; mysql>SET PASSWORD FOR 'root'0'127.0.0.1' = PASSWORD('newpwd'); mysql>SET PASSWORD FOR 'root'0' : :1' = PASSWORD (' newpwd' ) ; mysql>SET PASSWORD FOR 'root'0'host_name' = PASSWORD('newpwd');
You can also use a single statement that assigns a password to all root accounts by using UPDATE to
modify the mysąl .user table directly. This method works on any platform:
shell>raysql -u root
mysql>UPDATE raysql.user SET Password = PASSWORD('newpwd')
-■WHERE User = 'root'; 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.