不灭的焱

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2013-05-30 21:58:39  修改时间:2024-04-30 20:32:55  分类:MySQL/Redis  编辑

MySQL 的“root”用户默认状态是没有密码的,所以在 PHP 中您可以使用 mysql_connect("localhost","root","") 来连接 MySQL 服务器;

如果您想为 MySQL 中的“root”用户设置密码(例如:本机MySQL密码为 123456),请在控制台中使用“mysqladmin”命令。例如:

d:\PHP\xampp\mysql\bin\mysqladmin.exe  -u  root  password  123456

另外,如果是先前有秘密,则修改命令为:

d:\PHP\xampp\mysql\bin\mysqladmin.exe -u root -p password 123456

回车后提示你输入密码,输入“旧密码”即可。

请注意,更改 root 的密码之后,不要忘记更改 PHPMyAdmin 中的相关信息。在 ...xamppphpmyadmin 下搜索“config.inc.php”并编辑下面几行:

$cfg['Servers'][$i]['user'] = 'root'; // MySQL SuperUser
$cfg['Servers'][$i]['auth_type'] = 'http'; // HTTP MySQL authentification

从今往后,需要正确输入“root”的密码才能启动 PHPMyAdmin。

 

重启MySQL服务后新密码生效!

 

参考:

<?php

$cfg['blowfish_secret'] = 'a8b7_snsgou.com_c6d';

/* Servers configuration */
$i = 0;

/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['AllowNoPassword'] = false;