ubuntu修改mysql的root密码

1.sudo cat /etc/mysql/debian.cnf

dc2-user@10-254-0-118:/etc/mysql$ sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = 2FchlPccVYLhVFrZ
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = 2FchlPccVYLhVFrZ
socket   = /var/run/mysqld/mysqld.sock

2.# mysql -u  debian-sys-maint -p
enter password: <输入[client]节的密码>

然后进入mysql的交互界面。

3.格式:mysql> set password for 用户名@localhost = password('新密码');
例子:mysql> set password for root@localhost = password('123');

4.登陆的方法:

mysql -u root --password="123456"

 

posted @ 2018-10-29 13:41  chenzhigang  阅读(276)  评论(0编辑  收藏  举报