Symptoms
-
Repairing MySQL using Plesk repair utility fails:
# plesk repair mysql -v
The user user is absent from the database server ............... [ERROR]
Recreate the user user with default permissions and default hosts? [Y/n]
Recreating the user user ..................................... [FAILED]
- Operation CREATE USER failed for 'user'@'%'Error messages: 1; Warnings: 0; Errors resolved: 0
exit status 1
-
It is not possible to create a user manually:
# plesk db
mysql> CREATE USER 'user'@'%' IDENTIFIED BY 'password';
mysql> ERROR 1396 (HY000): Operation CREATE USER failed for 'user'@'%' - The migration might fail with the following error:
stderr: Unable to add database user: Operation CREATE USER failed for 'user'@'%'
Cause
Such user already exists or also it can be caused by the MySQL bug: https://bugs.mysql.com/bug.php?id=28331
Resolution
-
Connect to the server using SSH.
-
Create a dump of the database
mysql
:# MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysqldump -uadmin mysql > /root/mysql_db_backup_$(date "+%b-%d-%Y-%H-%M-%S").sql
-
Access MySQL server and switch to the database
mysql
:# plesk db
mysql> use mysql;
-
Remove the user mentioned in the error message:
mysql> DROP USER 'user'@'localhost';
-
Flush privileges from MySQL:
mysql> flush privileges;
-
Try again the operation of repairing or user creation.