Use the following steps to reset a MySQL root password by using the command line interface.

Stop the MySQL service

(Ubuntu and Debian) Run the following command:

sudo /etc/init.d/mysql stop

(CentOS, Fedora, and Red Hat Enterprise Linux) Run the following command:

sudo /etc/init.d/mysqld stop

Start MySQL without a password

Run the following command. The ampersand (&) at the end of the command is required.

sudo mysqld_safe --skip-grant-tables &

Connect to MySQL

Run the following command:

mysql -uroot

Set a new MySQL root password

Run the following command:

use mysql;

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

flush privileges;

quit

Stop and start the MySQL service

(Ubuntu and Debian) Run the following commands:

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

(CentOS, Fedora, and Red Hat Enterprise Linux) Run the following commands:

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

Log in to the database

Test the new password by logging in to the database.

mysql -u root -p

You are prompted for your new password.

Linux - Reset a MySQL root password的更多相关文章

  1. linux开机出现Give root password for maintenance (or type Control-D to continue):解决办法

    修改rc.local后导致 linux开机出现Give root password for maintenance,而且很多系统文件无法修改,之前的rc.local也不能修改了,单用户模式也无法进入 ...

  2. 运维笔记--linux下忘记mysql root密码

    补充链接:Windows下忘记密码处理: https://www.cnblogs.com/hellojesson/p/5972950.html 场景描述: Linux环境下忘记 root 密码, 1. ...

  3. mysql root password

    """centos:mysql忘记root密码解决 1.修改MySQL的登录设置: # vim /etc/my.cnf 在[mysqld]的段中加上一句:skip-gra ...

  4. linux下忘记mysql root密码解决办法

    vi /etc/my.cnf    #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables [mysqld] skip-grant-tables :wq!  #保存退出 s ...

  5. Linux下修改mysql root密码

    1.修改MySQL的配置文件(默认为/etc/my.cnf),在[mysqld]下添加一行skip-grant-tables 2.保存配置文件后,重启MySQL服务 service mysqld re ...

  6. linux 下解决mysql root 权限无法远程连接问题

    问题描述:MySQL数据库安装成功后,在服务器本地可以连接成功,但是使用工具navicat无法进行远程连接,如图: 原因:MySQL默认只允许root帐户在本地登录,如果要在其它机器上连接mysql, ...

  7. mysql forget root password

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

  8. linux 安装完mysql 密码重置

    If you have forgot the MySQL root password, can’t remember or want to break in….. you can reset them ...

  9. Give root password for maintenance

    linux开机出现"Give root password for maintenance (or type Control-D to continue):" 出现这种情况一般为两种 ...

随机推荐

  1. Jasper_crosstab_display a value of field in crosstab total row

    1.create a measure <measure name="myField" class="java.lang.String"> <m ...

  2. windows mongodb 安装

    window平台一下所有命令 务必以管理员身份运行 且在window系统命令行下,如git bash不可以 具体以管理员身份运行的快捷键是 1. win+x 2. shift + a 设置文件存储目录 ...

  3. 安装notepad++之后怎样在鼠标右键上加上Edit with notepad++

    在鼠标右键上加入使用notepad++编辑 我们在安装完notepad++文本编辑器之后,在一个文本文件上右键有时候并没有出现"使用notepad++编辑的选项",我们可以通过简单 ...

  4. 面试题 46 1+ 2+3+...+n

    class Temp{ public: Temp(){ ++N; sum+=N; } static void Reset(){ N = ; sum = ; } static int getSum(){ ...

  5. asp.net 中的错误跳转 customerrors 对html文件不起作用

    在配置web.config时发现customerrors对aspx文件是起作用的,我想通过customerrors来判断是否有html文件时,却不起作用? 这是为什么,如果要起作用.net里该如何操作 ...

  6. 关于Java集合的总结

    (一)List: ArrayList 以数组实现.节约空间,但数组有容量限制.超出限制时会增加50%容量,用System.arraycopy()复制到新的数组,因此最好能给出数组大小的预估值.默认第一 ...

  7. 线性时间构造普吕弗(Prüfer)序列

    tree -> sequence 首先预处理数组 deg[N], deg[i]表示编号为i的节点的度数,我们每次要删除的节点肯定是 满足deg[i]=1 的编号最小节点, 首先找到所有叶子并选出 ...

  8. 【案例】舒邑:一个女装品牌的奇葩打法-@i黑马

    [案例]舒邑:一个女装品牌的奇葩打法-@i黑马 [案例]舒邑:一个女装品牌的奇葩打法

  9. first move advantage_百度搜索

    first move advantage_百度搜索 先动优势

  10. python glob标准库基础学习

    #glob文件名模式匹配#作用:使用unix shell规则查找与一个模式匹配文件名"""尽管glob api很小,但这个模块很强大,只要程序需要查找文件系统中名字与某种 ...