Unable to install phptheadmin

phpmyadminraspbian

I have installed nginx on Raspberry Pi running Raspbian Stretch and installed WordPress
In the process I ran the following

sudo apt install mysql-server
sudo apt install php-mysql

I setup MariaDB and set up WordPress Database with

sudo mysql_secure_installation
sudo mysql -uroot -p
create database wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'redacted';

I have done some WordPress configuration, and wanted to backup my WordPress

I attempted to install phpmyadmin (sudo apt install phpmyadmin), but this keeps failing with error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
There seems to be no option to enter the password for root@localhost

I have tried to interrogate MariaDB which shows:-

MariaDB [(none)]> status
--------------
mysql  Ver 15.1 Distrib 10.1.23-MariaDB, for debian-linux-gnueabihf (armv7l) using readline 5.2

Connection id:      104
Current database:   
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server:         MariaDB
Server version:     10.1.23-MariaDB-9+deb9u1 Raspbian 9.0
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:        /var/run/mysqld/mysqld.sock
Uptime:         18 hours 43 min 19 sec

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+

So no phpmyadmin database seems to have been created.

Can anyone help me install phpmyadmin ?

Would manually creating database phpmyadmin help?


EDIT

Based on the answer by @Kramer this seemed to be a known problem with Debian (I thought Debian packages were meant to be checked).

I have now performed the following steps (file locations differed from suggested)

cd /usr/share/phpmyadmin/sql/
create database phpmyadmin;

mysql -u root -p < create_tables.sql

    create database phpmyadmin;
    grant all privileges on phpmyadmin.* to phpmyadmin@localhost identified by "redacted";

    Grant USAGE ON mysql.* TO phpmyadmin@localhost;
    GRANT SELECT ON mysql.db TO phpmyadmin@localhost;
    GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON mysql.tables_priv TO phpmyadmin@localhost;
    GRANT SELECT (Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv) ON mysql.user TO phpmyadmin@localhost;
    GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO  phpmyadmin@localhost;

I configured nginx by adding the following to /etc/nginx/sites-available/default as per https://www.linuxbabe.com/linux-server/install-phpmyadmin-nginx-ubuntu-16-04

location /phpmyadmin {
  root /usr/share/;
  index index.php;
  try_files $uri $uri/ =404;

  location ~ ^/phpmyadmin/(doc|sql|setup)/ {
    deny all;
  }

  location ~ /phpmyadmin/(.+\.php)$ {
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }
 }

Navigating to your-domain.com/phpmyadmin/ and logging in as phpmyadmin showed phpMyAdmin.
I thought success!, however on navigating to Databases I received the following errors:-

mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES)  
Connection for controluser as defined in your configuration failed.

It seems the earlier attempt had created/modified files in /etc/phpmyadmin/ which is trying to use the missing password (as per the installation log)

Creating config file /etc/phpmyadmin/config-db.php with new version
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO).
unable to connect to mysql server.
error encountered creating user:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
dbconfig-common: phpmyadmin configure: trying again.
Determining localhost credentials from /etc/mysql/debian.cnf: succeeded.
dbconfig-common: writing config to /etc/dbconfig-common/phpmyadmin.conf
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO).
unable to connect to mysql server.
error encountered creating user:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
dbconfig-common: phpmyadmin configure: trying again.
Determining localhost credentials from /etc/mysql/debian.cnf: succeeded.
dbconfig-common: writing config to /etc/dbconfig-common/phpmyadmin.conf
Replacing config file /etc/dbconfig-common/phpmyadmin.conf with new version
Replacing config file /etc/phpmyadmin/config-db.php with new version
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO).
unable to connect to mysql server.
error encountered creating user:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Best Answer

First of all, the error you are getting is because some script is trying to execute mysql with no password as root: either you are root or you are using sudo:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Assuming your MySQL root user has passwords, you would need to access or interact with MySQL CLI as: mysql -u username -p and password will be requested bellow.

An easy (but not recommended fix) would be to remove the MySQL password for root, perform the whole installation and then re-establish the password. This will allow the installation script to complete fine.

The right way to fix this would be to manually locate the CREATE DATABASE command at the installation script and run it manually by using the mysql command syntax above (using username and password).

create the configuration storage

  1. go to the phpMyAdmin samples: cd ${installation_path}/phpmyadmin/examples
  2. Import the sample: # mysql -u root -p < create_tables.sql (this will execute the script that is failing on your installation and will prompt for password)
  3. Restart NGINX: # systemctl restart nginx

Source http://howtolamp.com/lamp/phpmyadmin/4.2/installing#configuration-storage

Also, the doc for phpmyadmin states specific steps for Debian, which I guess will be similar at Raspbian : https://docs.phpmyadmin.net/en/latest/setup.html#linked-tables

Related Question