---
title: "mysql创建用户和忘记root密码"
author: "pujing"
date: "2011-04-21T01:21:45Z"
tags: []
categories: ["操作系统"]
slug: "mysql-root"
draft: false
lastmod: "2011-04-21T01:22:13Z"
id: 1010682
url: "https://pujing.iteye.com/blog/1010682"
---

1.创建mysql用户

> grant  all on myidb.* to  myidb@'localhost' identified by'password';
> revoke all on myidb.* from  myidb@'localhost';

 
 
说明：
除grant/revoke命令，其他与权限相关的修改都要执行flush privileges 才能生效。
 
 
2.修改mysql的root用户密码

> mysql>use mysql
> mysql>update user set password=PASSWORD('Newpasswor') whereuser='root';
> #/etc/rc.d/init.d/mysqld restart

 
 
3.忘记mysql的root密码

> 1)vi /etc/my.cnf
> 2)在[mysqld]下加入一行 skip_grant_tables
> 3)#/etc/rc.d/init.d/mysqld restart
> 4)#mysql -u root
> 5)mysql>use mysql;
>   mysql>update user setpassword=PASSWORD('Newpassword') where user='root'