linux修改mysql密码

使用宝塔安装mysql后,忘记了初始密码。在linux下如何修改mysql的密码呢?

我的服务器环境:

        CentOS Linux 7.2.1511    宝塔7.0.3   mysql 5.7.26(版本不一样,操作可能不一样)

    步骤:

  1. 在宝塔中修改mysql配置文件,mysqld区段中添加 skip-grant-tables
    宝塔mysql配置
    宝塔mysql配置
  2. 重启mysql

        在xshell中输入:service mysqld restart

    3. 重新进入 mysql,此时进入是不需要输入密码的

开启mysql
开启mysql

    4.修改密码(操作mysql中的user表)

       

操作user表
操作user表

      use mysql; 

       update user set authentication_string = password('your password') where user ='root';

 注意:我的是5.7版本的,所以用的 authentication_string,低版本使用 password = password('your password')

  5.将配置文件中添加的行删除 skip-grant-tables

发布了11 篇原创文章 · 获赞 33 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_26902237/article/details/103897411