修改mysql数据库的密码 发表于 2018-06-25 | 分类于 Sql 一、用SET PASSWORD命令12345首先登录MySQL格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:mysql> set password for root@localhost = password('123'); 二、用mysqladmin123格式:mysqladmin -u用户名 -p旧密码 password 新密码 例子:mysqladmin -uroot -p123456 password 123 三、用UPDATE直接编辑user表12345678首先登录MySQL。 mysql> use mysql; mysql> update user set password=password('123') where user='root' and host='localhost'; mysql> flush privileges; 五、忘记root密码123456789101112131415161718192021222324252627282930313233341.修改MySQL的登录设置:在[mysqld]的段中加上一句:skip-grant-tables vi /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock skip-grant-tables 2. 重启服务service mysql restart3. 修改 root 密码mysql -u root -pmysql> USE mysql;mysql> UPDATE user SET Password = password('123456') WHERE User = 'root';mysql> flush privileges;mysql> quit;4. 删除刚刚新增加的 skip-grant-tables vi /etc/my.cnf5. 重启服务service mysql restartmysql -u root -pSET PASSWORD = PASSWORD('whatyoulike');