Migrating to another server fails at restoring the database

I have NC19 on Ubuntu 18.04 with php7.3. Before upgrading the production server I want to clone this server to a testserver and test the upgrading there first.
I therefore have setup a testserver with the same configuration. I follow the instructions to backup and restore a server as described here Nextcloud Sicher- & Wiederherstellung – Carsten Rieger IT-Services
but I do the backup from the production server and the restore to the test server.
When I restore the database with the command
mysql -h localhost -unextcloud -pnextcloud nextcloud < /home/osusername/ncdb_6.sql

I get an error
ERROR 1045 (28000): Access denied for user ‘nextcloud’@‘localhost’ (using password: YES)

According to the config.php in both instanses
‘dbname’ => ‘nextcloud’,
‘dbhost’ => ‘localhost’,

‘dbuser’ => ‘nextcloud’,

What is wrong?

Did you setup a user nextcloud on your database server and the corresponding database nextcloud? It’s done in step 6 of your tutorial.

Don’t forget to flush privileges (or restart the database server after that)!

Thanks for answer
The two servers are almost identical. In the config.php the name, host and user are identical

‘dbname’ => ‘nextcloud’,
‘dbhost’ => ‘localhost’,

‘dbuser’ => ‘nextcloud’,
The two servers have been set up since long and both have been working normally. I just now want to create a clone of the production server using the testserver

I follow the instructions from Nextcloud Sicher- & Wiederherstellung – Carsten Rieger IT-Services

Here are the commands I used for copying the production server:
sudo -s
sudo -u www-data php7.3 /var/www/nextcloud/occ maintenance:mode --on
tar -cpzf /home/osusername/ncserver_date +"%w".tar.gz -C /var/www/nextcloud .
tar -cpzf /home/osusername/ncdata_date +"%w".tar.gz -C /var/nc_data .
mysqldump --single-transaction --routines -h localhost -unextcloud -pnextcloud nextcloud > /home/osusername/ncdb_date +"%w".sql
sudo -u www-data php7.3 /var/www/nextcloud/occ maintenance:mode --off

I transferred to resulting .tar.gz files and the sql file to the testserver.

I then used these commands on the testserver to install the NC-setup, data and database from the copies:

sudo -s
sudo -u www-data php7.3 /var/www/nextcloud/occ maintenance:mode --on
/usr/sbin/service nginx stop
/usr/sbin/service php7.3-fpm stop
rm -r /var/www/nextcloud/
rm -r /var/nc_data/
mkdir -p /var/www/nextcloud/
mkdir -p /var/nc_data/
tar -xpzf /home/osusername/ncserver_1.tar.gz -C /var/www/nextcloud/
tar -xpzf /home/osusername/ncdata_1.tar.gz -C /var/nc_data/
chown -R www-data:www-data /var/nc_data /var/www
mysql -h localhost -uroot -pnextcloud -e “DROP DATABASE nextcloud”
mysql -h localhost -uroot -pnextcloud -e “CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci”
mysql -h localhost -uroot -pnextcloud -e “GRANT ALL PRIVILEGES on nextcloud.* to nextcloud@localhost”

mysql -h localhost -unextcloud -pnextcloud nextcloud < /home/osusername/ncdb_1.sql

** At this command I got the error
ERROR 1045 (28000): Access denied for user ‘nextcloud’@‘localhost’ (using passwo rd: YES) **

Do you mean there should be a FLUSH PRIVILEGES; command before that command?

So could not finish the last commands
/usr/sbin/service php7.3-fpm start /usr/sbin/service nginx start

sudo -u www-data php7.3 /var/www/nextcloud/occ maintenance:data-fingerprint
sudo -u www-data php7.3 /var/www/nextcloud/occ maintenance:mode --off

On the testserver I can access the nextcloud database by:
mysql nextcloud -p (get asked for the password)

and have these users

select host, user, password from mysql.user;
±----------±----------±------------------------------------------+
| Host | User | Password |
±----------±----------±------------------------------------------+
| localhost | root | *712B898EEBA00274D684A06E4D18CC1AFD2179F0 |
| localhost | mysql | invalid |
| localhost | nextcloud | *712B898EEBA00274D684A06E4D18CC1AFD2179F0 |
±----------±----------±------------------------------------------+

but this command
sudo mysql -u nextcloud -p

gives an error
ERROR 1045 (28000): Access denied for user ‘nextcloud’@‘localhost’ (using password: YES)

How can I grant access for the user nextcloud

Did you restart the database server? Either it has not taken into account the changes yet or there is something else that you have to allow logins from localhost. If you have phpmyadmin or something similar, it’s easier to go through all the settings of the user.

I have only made the commands as shown. Can you help me formulate a command. I am almost a beginner related do Linux and MySQL.

I logged in to mysql and did the changes from within mysql
DROP DATABASE nextcloud;
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES on nextcloud.* to nextcloud@localhost IDENTIFIED BY ‘nextcloud’
FLUSH PRIVILEGES;
exit;

and then this command was accepted
mysql -unextcloud -pnextcloud nextcloud < /home/rollanders/ncdb_6.sql

I completed the remaining commands

I had to change trusted domain. The testserver now looks like a clone of the production server.

@riegerCLOUD perhaps something to add to your restoring tutorial…