通过root访问服务器,我将如何更改mysql root密码?

时间:2012-05-29 00:41:16

标签: mysql sql

  

可能重复:
  How do I change the password of the root user in MySQL?

我有root访问ec2实例,但我不知道mysql root密码是什么,我需要它。我怎么能1)找到这个?或者2)重新安装mysql并给自己一个root密码?

1 个答案:

答案 0 :(得分:1)

$ sudo service mysql stop
$ /usr/bin/mysqld_safe --skip-grant-tables &
mysql -h localhost
> use mysql
> update user set password = password('') where user = 'root' and host='localhost';
> quit
$ sudo service mysql start
$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.