MYSQL root user is being denied permission while installing an app

I just tried to install ownCloud with Moulinette and this is the error I’m getting (private parts like usernames/passwords have been changed):

root@yunohost:/var/www/owncloud# yunohost app install owncloud
Downloading…
sh: 0: getcwd() failed: No such file or directory
Extracting…
sh: 0: getcwd() failed: No such file or directory
Done.
sh: 0: getcwd() failed: No such file or directory
sh: 0: getcwd() failed: No such file or directory
sh: 0: getcwd() failed: No such file or directory
sh: 0: getcwd() failed: No such file or directory
sh: 0: getcwd() failed: No such file or directory
sh: 0: getcwd() failed: No such file or directory
sh: 0: getcwd() failed: No such file or directory
Choose a domain for Owncloud: subdomain.mydomain.tld
Choose a path for Owncloud (default: /owncloud): /
Choose the Owncloud administrator (must be an existing YunoHost user): myuser
Executing script…

  • set -e
  • APP=owncloud
    ++ echo -n own
    ++ echo cloud
  • APPNAME=owncloud
    ++ echo -n owncloud
    ++ echo -8.2.0
  • SOURCES=owncloud-8.2.0
  • domain=subdomain.mydomain.tld
  • path=/
  • user=myuser
  • grep -qi ‘“username”: “myuser”’
  • sudo yunohost user list --json
  • sudo yunohost app setting owncloud admin_user -v myuser
  • sudo yunohost app checkurl subdomain.mydomain.tld/ -a owncloud
  • path=
  • sudo apt-get update -qq
  • sudo apt-get install acl smbclient php5-cli php-apc coreutils gnupg tar -y -qq
    ++ sed -n ‘s/(.{24}).*/\1/p’
    ++ tr -c -d A-Za-z0-9
    ++ dd if=/dev/urandom bs=1 count=200
  • db_pwd=databasepassword
  • db_user=owncloud
  • sudo yunohost app initdb owncloud -p password
    ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
    Error: MySQL database creation failed
    Error: Installation failed

I haven’t changed the password for root a far as I can remember, so I’m not sure if it’s a password or a permissions issue. How do I give root access again to get past this?

Hello,
The system is using the password stored in /etc/yunohost/mysql. You can check if it works or not by typing

mysql -u root -p$(cat /etc/yunohost/mysql) mysql

I guess you will have “ERROR 1045 (28000)” again, so just to be sure you can set back its password as follows (logged in as root):

service mysql stop
mysqld --skip-grant-tables

In another shell (still as root):

cat /etc/yunohost/mysql
(copy somewhere the password)
mysql mysql
mysql> set password for 'root'@'localhost' =  PASSWORD('thepassword');
mysql> set password for 'root'@'::1' =  PASSWORD('thepassword');
mysql> set password for 'root'@'127.0.0.1' =  PASSWORD('thepassword');
mysql> exit
ps ax | grep mysql
kill THE_TWO_PIDS_FOR_MYSQLD_SAFE
service mysql start

This page may also help: https://wiki.labriqueinter.net/doku.php/howto:fix_self_corrupt_mysql

Martin

2 Likes

Thanks Martin;

When I tried exactly what you have here, Mysql gave an error about not being able to run the set password line because it was running with the skip grant tables option. After some searching around though, I found another way of doing that line that worked, namely:

update user set password=PASSWORD(“THE-NEW-ROOT-PASSWORD”) where User=‘root’;

Now it’s running into a new (no Mysql) permissions error below though at the gpg --import …/sources/owncloud.asc line, saying:

failed to create temporary file `/home/admin/.gnupg/.lk0x7db0b0.yunohost.10628’: permission denied

The strange thing is that it’s running as root, has already successfully executed a number of sudo commands and doing touch /home/admin/.gnupg/test works fine.

Here’s the full output:

yunohost app install owncloud;
Downloading...
Extracting...
Done.
Choose a domain for Owncloud: subdomain.mydomain.tld
Choose a path for Owncloud (default: /owncloud): /
Choose the Owncloud administrator (must be an existing YunoHost user): myusername
Executing script...
+ set -e
+ APP=owncloud
++ echo -n own
++ echo cloud
+ APPNAME=owncloud
++ echo -n owncloud
++ echo -8.2.0
+ SOURCES=owncloud-8.2.0
+ domain=subdomain.mydomain.tld
+ path=/
+ user=myusername
+ grep -qi '"username": "myusername"'
+ sudo yunohost user list --json
+ sudo yunohost app setting owncloud admin_user -v myusername
+ sudo yunohost app checkurl subdomain.mydomain.tld/ -a owncloud
+ path=
+ sudo apt-get update -qq
+ sudo apt-get install acl smbclient php5-cli php-apc coreutils gnupg tar -y -qq
++ sed -n 's/\(.\{24\}\).*/\1/p'
++ tr -c -d A-Za-z0-9
++ dd if=/dev/urandom bs=1 count=200
+ db_pwd=XXXXXXXXXX
+ db_user=owncloud
+ sudo yunohost app initdb owncloud -p XXXXXXXX
Success! MySQL database successfully initialized
+ sudo yunohost app setting owncloud mysqlpwd -v XXXXXXXX
+ trap exit_properly ERR
+ sudo useradd -d /var/www/owncloud owncloud
+ sha256sum --strict --quiet -c ../sources/owncloud-8.2.0.tar.bz2.sha256sum
+ gpg --import ../sources/owncloud.asc
gpg: failed to create temporary file `/home/admin/.gnupg/.#XXXXXXXX.yunohost.XXXXXXXX': Permission denied
gpg: keyblock resource `/home/admin/.gnupg/secring.gpg': general error
gpg: failed to create temporary file `/home/admin/.gnupg/.#XXXXXXXX.yunohost.XXXXXXXX': Permission denied
gpg: keyblock resource `/home/admin/.gnupg/pubring.gpg': general error
gpg: no writable keyring found: eof
gpg: error reading `../sources/owncloud.asc': general error
gpg: import from `../sources/owncloud.asc' failed: general error
gpg: Total number processed: 0
++ exit_properly
++ set +e
+++ sudo cat /etc/yunohost/mysql
++ root_pwd=XXXXXXXX
++ mysql -u root -pXXXXXXXX -e 'DROP DATABASE owncloud ; DROP USER owncloud@localhost ;'
++ sudo rm -f /etc/php5/fpm/pool.d/owncloud.conf
++ sudo killall php5-fpm
++ sudo service php5-fpm start
Failed to open /dev/tty: No such device or address
++ sudo userdel owncloud
++ sudo rm -Rf /var/www/owncloud
++ exit 1
Error: Installation failed

I had the same issue. Here are the steps to solve it.

1 . Stop mysql service

service mysql stop

2 . Start to MySQL server w/o password:
use mysqld_safe:

mysqld_safe --skip-grant-tables &

Output:

170403 17:38:46 mysqld_safe Logging to '/var/lib/mysql/domain.com.err'.
170403 17:38:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

3 . Connect to mysql server using mysql client:

# mysql -u root

Output:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.0.30-MariaDB-0+deb8u1 (Debian)

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>

4 . Setup new MySQL root user password

mysql> use mysql;
mysql> update user set password=PASSWORD("**NEW-ROOT-PASSWORD**") where User='root';
mysql> flush privileges;
mysql> quit

5 . Start MySQL server and test it:

service mysql start
mysql -u root -p
2 Likes

Hi. I’ve been having this same error, which prevents me from upgrading nextcloud. I have tried both solutions above. The first solution failed with errors. The second solution (from kanhu), seemed to work (step 5 produces no error). I tried upgrading nextcloud with those processes open, and again after a server reboot. It still fails with the same error:

mysqldump: Got error: 1045: “Access denied for user ‘root’@‘localhost’ (using password: YES)” when trying to connect

Could I solve this my purging/reinstalling mysql? Would that wreck yunohost or nextcloud?

Do

$ yunohost service --regen-conf mysql -f

Basically you have to change the password and put in /etc/yunohost/mysql.

1 Like

Ok, it is finally working. Thank you very much. In the end, I don’t entirely understand what I did/didn’t need to do, but I think it went like this:

-Steps 1-4 above
-sudo nano /etc/yunohost/mysql (edit password here to match new password from step 4)
-sudo yunohost service regen-conf mysql -f
-step 5 from above
-reboot

After that, I was able to upgrade nextcloud :slight_smile:

3 Likes