mysql forget root password

http://www.rackspace.com/knowledge_center/article/mysql-resetting-a-lost-mysql-root-password

MySQL - Resetting a lost MySQL root password

The MySQL root password allows full access to the MySQL database and allows for all actions to be undertaken including creating new users, new databases, setting access rules and so on.

Losing one can be a difficult issue to encounter. Luckily, resetting the root password is easy as long as you have sudo access to the Server.

Contents

Not the Server root user

A common issue is confusing the Server root user with the MySQL root user.

The Server root user is the server‘s main user. The MySQL root user has complete control over MySQL only. The two ‘root‘ users are not connected in any way.

Stop MySQL

The first thing to do is stop MySQL. If you are using Ubuntu or Debian the command is as follows:

sudo /etc/init.d/mysql stop

For CentOS, Fedora, and RHEL the command is:

sudo /etc/init.d/mysqld stop

Safe mode

Next we need to start MySQL in safe mode - that is to say, we will start MySQL but skip the user privileges table. Again, note that you will need to have sudo access for these commands so you don‘t need to worry about any user being able to reset the MySQL root password:

sudo mysqld_safe --skip-grant-tables &

Note: The ampersand (&) at the end of the command is required.

Login

All we need to do now is to log into MySQL and set the password.

mysql -u root

Note: No password is required at this stage as when we started MySQL we skipped the user privileges table.

Next, instruct MySQL which database to use:

use mysql;

Reset Password

Enter the new password for the root user as follows:

update user set password=PASSWORD("mynewpassword") where User=‘root‘;

and finally, flush the privileges:

flush privileges;

Restart

Now the password has been reset, we need to restart MySQL by logging out:

quit

and simply stopping and starting MySQL.

On Ubuntu and Debian:

sudo /etc/init.d/mysql stop
...
sudo /etc/init.d/mysql start

On CentOS and Fedora and RHEL:

sudo /etc/init.d/mysqld stop
...
sudo /etc/init.d/mysql start

Login

Test the new password by logging in:

mysql -u root -p

You will be prompted for your new password.
时间: 2024-10-14 12:32:26

mysql forget root password的相关文章

MYSQL更改root password时遇到Access Denied的解决办法

今天在公司虚拟机上装MYSQL之后需要修改root password,然而遇到这样的错误: Access denied for user 'root'@'localhost' (using password:YES) 后来在网上搜了下,找到如下解决办法,测试可用. # /etc/init.d/mysql stop# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &# mysql -u root mysqlmysql&g

windows下新安装的mysql修改root password问题

常用步骤: 1. 在my.ini中的mysqld下添加一行 skip-grant-tables 2.重启mysql后直接进入后,用SQL直接修改password列: C:\> net stop mysqlC:\> net start mysql C:\> mysqlmysql>mysql> use mysqlDatabase changedmysql> UPDATE user SET Password=PASSWORD('newpassword') where USER

MySQL reset root password

大概步骤如下: 1:停止mysql服务器 2:使用mysqld_safe启动mysql 3:修改root密码 4:退出,重启mysql服务器 步骤一:停止mysql服务器的几个方法如下: 1. 通过 service mysqld stop 来停止mysql 2. 如果不行,则直接使用kill命令停止myqld服务,首先需要使用 ps aux | grep mysql 来查看mysql相关的进程pid,(使用ps aux可以看到pid为第二列),然后使用 kill -9 XXXX 依次杀掉 步骤二

Reset root password in CentOS 7 / RHEL 7

There may be some occasion you will end up with requirement to reset the root password, the occasion comes when you forget root password; follow this guide to reset the password of root. In CentOS, single user mode will help us to achieve our goal of

MYSQL安装时解决要输入current root password的解决方法

在装MYSQL的时候发现要输入current root password不记得以前在电脑里装过(你的系统曾经装过MYSQL在重装就会要求输入原来设定的密码,如果是第一次安装就不会出现),在网上苦苦搜寻解决方法. 终归结出以下解决方法: 1.清除MYSQL的安装目录,默认是C:\Program Files 2.清除MYSQL数据存放目录,一般在C:\Documents and Settings\All Users.windows\Application Data目录下 (需要注意的时Applica

MySQL忘记root密码后修改

MySQL忘记root密码后可以使用下面的方法修改. 1.登录MySQL所在的服务器,手工kill掉MySQL进程 kill `cat $mysql_data_dir/hostname.pid` $mysql_data_dir/hostname.pid为MySQL数据目录,它记录了MySQL服务的进程号. [[email protected] ~]# ps -ef |grep mysql root      6602     1  0 21:39 ?        00:00:00 /bin/s

MySQL修改root密码的多种方法

方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass'); 方法2:用mysqladmin mysqladmin -u root password "newpass" 如果root已经设置过密码,采用如下方法 mysqladmin -u root password oldpass "newpass" 方法3: 用UPDA

第三篇 ubuntu下,mysql 的root用户密码忘了怎么办?

好长一段时间没有使用ubuntu了,今天进来玩玩,结果连mysql的root用户密码都忘记了.就上网找了一下,发现如下解决办法,试了一下,可行!记录在此,环境问题,是需要注意的. Ubuntu Server 12.04 LTS,用 apt-get 安装 MySQL 过程中没有提示设置 root 账号的密码,安装完成后发现 root 空密码无法登录. 解决方案: 其实 debian 系的 MySQL 安装过程中会设置一个默认的账户,这个文件里保存了默认账号的信息 cat /etc/mysql/de

How To Reset Your Forgotten Root Password On CentOS 7 Servers

Sometimes you forget stuff. I do. I forget important passwords for important websites sometimes. Retrieving your forgotten passwords for most websites is easy, all one has to do remember few details that were used when signing up for the service to g