Home  >  Article  >  Database  >  初始化mysql 用户的密码_MySQL

初始化mysql 用户的密码_MySQL

WBOY
WBOYOriginal
2016-06-01 13:11:311071browse

首次安装mysql后,使用root登录mysql。终端会提示需要输入密码。可是安装的过程并没有提示输入root的密码。怎么办呢?通过修改my。conf配置绕开mysql的授权验证,重置root用户的密码。操作过程如下
1)先停止当前正在运行的mysql服务

/etc/init.d/mysql stop

2)修改my.conf
将下面的语句加入到 my.conf 文件中

#skip-grant-tables

保存退出
3)重新启动mysql服务
4) mysql -hlocalhost -root 直接进入到mysql的管理终端

use mysql ;//使用mysql数据库   update user set password=password('newpassword') where user=root ;//修改root用户的密码   flush privileges  ;//刷新   quit ;//退出

5)还原my.conf 文件
在skip-grant-table前加#号

skip-grant-table

6)重启mysql服务
/etc/init.d/mysql restart
7)mysql -hlocalhost -uroot -p //此时输入正确的root密码可以正常登录

//

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn