/ 中存储网

如何修改Linux服务器的MySQL数据库root密码

2014-12-27 15:41:00 来源:中存储网

第一种方法:
/local/server/mysql/bin/mysqladmin -u root password ‘new_password’
由于mysql安装的时候,默认没有root密码,安装时可用此方法设置root的密码。
[root@uc ~]# /local/server/mysql/bin/mysqladmin -u root password 'zhcw123'
/local/server/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
[root@uc ~]#

第二种方法:
登录mysql数据库/local/server/mysql/bin/mysql -u root -pzhcw123
[root@uc ~]# /local/server/mysql/bin/mysql -u root -pzhcw123
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 61
Server version: 5.0.90zhcw-log Source
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> use mysql
Database changed
mysql>
mysql>UPDATE user SET password=PASSWORD(’new_password’) WHERE user=’root’;
mysql>FLUSH PRIVILEGES;

第三种方法:
mysql>SET PASSWORD FOR root=PASSWORD(’new_password’);