简体   繁体   中英

How to change mysql user password?

Hi I am change mysql user password using bellow script but password does not change.

$conn = mysqli_connect('host', 'root', 'password');
$dbUser = "username"; # same username as in your example
$dbPass = "new_password"; # new password

$queries = array(
  "USE mysql;", # switch to the 'mysql' database
  "SET PASSWORD FOR '$dbUser'@'localhost' = PASSWORD('$dbPass');"
);

foreach($queries as $query) {
    $rs = mysqli_query($conn, $query);          
}

Using this script password does not change and no error display.

Try this, this can also help for sql injection.

$query = sprintf("UPDATE mysql.user SET Password = '%s' WHERE User='%s'",mysqli_real_escape_string($dbPass),mysql_real_escape_string($dbUser));
$result = mysqli_query($query);
if($result){
   echo "change success";
}

试试这个查询可能会帮助你

mysql_query("UPDATE mysql.user SET Password = PASSWORD('$password') WHERE User='$username'");

只需尝试此查询

SET PASSWORD FOR 'bob'@'%.example.org' = PASSWORD('cleartext password');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM