Database user creation not working on MySQL 8
Dear all,
I would like to ask for your support if you have a solution but haven't postid it yes (I could not find any solution on Google) to how to fix database user creation function where db server is MySQL 8.
There is an SQL syntax error on creation due to PASSWORD() function has been removed (ALSO DECRAPTED ON MYSQL 5.7 !!!) and the logic of user creation is also changed: we have to use CREATE USER function first then on a second command GRANT permissions for our newly created user.
I have checked mysql_clientdb_plugin.inc.php but I have to admit I could not get what's the idea behind.
I'm running my MySQL 8 server with mysql_native_password support due for better compatibility.
I tried to get rid of PASSWORD() function by double SHA1 the password with a PHP function:
function sqlPassword($input) {
$pass = strtoupper(
sha1(
sha1($input, true)
)
);
$pass = '*' . $pass;
return $pass;
}
Plus also extend the SQL command of a new user but without success:
if(!$link->query("CREATE USER ".$link->escape_string($database_user)."'@'$db_host'"." IDENTIFIED WITH mysql_native_password BY '".$link->escape_string($database_password_native)."';");
if(!$link->query("GRANT " . $grants . " ON `".$link->escape_string($database_name)."`.* TO '".$link->escape_string($database_user)."'@'$db_host';")) $success = false;
Any help would be appreciated!
Thank you!