MySQL root密码修改

我们知道,MySQL单独产品安装的时候可以在安装过程中设置root密码,而在绑定产品中(如XAMPP/PHPMyAdmin)一般默认root密码为空,但数据库root默认权限最高,如果是没有密码则非常危险,那如何修改root密码呢?

以XAMPP为例,我们按以下步骤测试成功。

1、修改phpMyAdmin配置文件config.inc.php:

打开phpMyAdmin目录,一般位于%xampp_installdir%/phpMyAdmin/config.inc.php

打开config.inc.php文件找到如下行并将其 auth_type改为'http' 或 'cookie'

$cfg['Servers'][$i]['auth_type']            = 'cookie';

2、编辑MySQL配置文件my.ini:

windows: %MySQL _installdir%/my.ini 
linux: /etc/my.cnf

搜索[MySQLd]并在其配置段添加如下一行:
skip-grant-tables

保存退出编辑。

3、重启MySQL 服务

windows:
net stop MySQL
net start MySQL

linux:
/etc/init.d/MySQLd restart

4、设置新的ROOT密码

在命令行下执行:
mysql -u root -p;

(i.e: C:/../mysql/bin>mysql -u root -p

Enter password:)

直接回车无需密码即可进入数据库了(若MySQL初始root密码为空),这时可以看到如下提示信息:


Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 15
Server version: 5.1.41 Source distribution

Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.

现在我们执行如下语句把root密码更新为 admin:
update user set password=PASSWORD("admin") where user='root';

quit 退出MySQL。

5、还原配置文件并重启mysql服务

然后修改MySQL 配置文件把刚才添加的那一行删除。

再次重起MySQL服务,密码修改完毕。

修改完毕。

用新密码 admin 试一下吧,又能登入MySQL 了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值