bitscn.com
method 1:
在/usr/local/mysql/bin/下:
./mysqladmin -u root password new_password
一般安装时用此方法设置。
method 2:
在mysql状态下:
mysql>update user set password=password(new_password) where user=root;
mysql>flush privileges;
method 3:
mysql>set password for root=password(new_password);
有人会问如果不知道mysql root的密码情况下,是否可以修改密码呢?答案:可以的,想知道方法请继续往下看:
只有在mysqld启动的时候加上 --skip-grant-tables就ok,
例:
[root@server]# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
[root@server]# /usr/local/mysql/bin/mysql -uroot -p
enter password:
welcome to the mysql monitor. commands end with ; or g.
your mysql connection id is 7
server version: 5.0.45-log source distribution
type help; or h for help. type c to clear the buffer.
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(******)where user=root;
query ok, 4 rows affected (0.00 sec)
rows matched: 4 changed: 4 warnings: 0
mysql> flush privileges;
query ok, 0 rows affected (0.01 sec)
杀掉mysql的进程或者重新启动mysql,然后重新登录,密码生效。
bitscn.com
