初始化mysql 用户的密码

来源:互联网 发布:百视通网络电视要密码 编辑:程序博客网 时间:2024/06/03 11:37

首次安装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前加#号
6)重启mysql服务

/etc/init.d/mysql restart 

7)mysql -hlocalhost -uroot -p //此时输入正确的root密码可以正常登录

0 0
原创粉丝点击