0

I am doing a LAMP installation for the first time.

I installed Apache, PHP, and MySQL flawlessly on my Ubuntu 16.04 through the terminal. The last thing that I installed was PHPMyAdmin. After I installed it I accidentally typed my username as phpmyadmin and some password. After that when I try to login and create a database, it says No Privilege.

I also tried default "root" with and without a password, but I still can't login. Then I tried to reinstall it, and also I tried dpkg-reconfigure, but it gave me some error message which had options like abort, retry, etc.

I also tried to remove all of the PHPMyAdmin data/files, and cleared all my browsing history as well as my cookies. The last thing that I tried was to use an alternative database software - Adminer. After I installed the software, it didn't ask me to setup an admin account.

When I tried to use it, I couldn't login because I don't know what the user was. I tried 'root' with or without password but still couldn't login. When I tried to login to my account in PHPMyAdmin, I was surprised that it worked and logged in. Unfortunately I still can't create a database and it has a dialogue like PHPMyAdmin : 'Access denied for user 'phpmyadmin'@'localhost'.

karel
  • 114,770
dar
  • 1
  • phpmyadmin has no security mechanism of its own. It uses the parameters of the MySQL database, which you store in its configuration file called config.inc.php in the top level. – Jos Oct 04 '16 at 07:25

2 Answers2

1

Uninsalling phpadmin will not remove accounts from the mysql database. You can do that manually, but you would have to have root access.

You can recover root access with these steps.

From the terminal stop the mysql service, then load it without grant tables. In the steps bellow the text after the $ sign is the commands you input. The text in the parenthesis are explanations and comments.

(Stop the database)

$ sudo systemctl stop mysql

(Start Mysql without loading the grant tables)

$ sudo mysqld_safe --skip-grant-tables &

(Now log into mysql as root with no password)

$ sudo mysql --user=root mysql

(Set the root's password with:)

mysql> update user set authentication_string=PASSWORD('new-password') where user='root';
mysql>flush privileges;
mysql> quit;

(Kill the safe-mode server the "$" is the prompt. Hit the "%" and press ENTER)

$ %

Cntrl+c

(Now restart the database and you're all set)

$ sudo systemctl start mysql

Review this answer for details:
mysql don't ask for root password when installing

L. D. James
  • 25,036
0

I was looking for a solution to reset the MySQL root password on Ubuntu 22.04 and found this question and solution.

I remember following the steps outlined by L.D. James when I installed LAMP on Ubuntu 18.04. However it did not work with the MySQL distribution installed with php on Ubuntu 22.04 from the Ubuntu repositories.

When you run the code

$ sudo mysqld_safe --skip-grant-tables &

it throws the following errors.

$ sudo mysqld_safe --skip-grant-tables & [2] 4495 $ 2022-07-22T11:13:52.549114Z mysqld_safe Logging to '/var/log/mysql/error.log'. 2022-07-22T11:13:52.550637Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

[2]- Exit 1 sudo mysqld_safe --skip-grant-tables $ sudo mysql --user=root mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) $

This is because the directory mysqld in the file path /var/run/mysqld doesn’t seem to exist.

This is what I did (having first installed Canonical's Ubuntu distribution of php for Ubuntu 22.04 )

Ensure that mysql is running.

$ sudo systemctl start mysql

Next, connect to mysql

$ sudo mysql

You should something like

“Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.29-0ubuntu0.22.04.2 (Ubuntu)..etc”

Next in the mysql prompt run:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Note: replace ‘password’ with the password you want to set for root.

The statement should return “Query OK, 0 rows affected (0.00 sec)”

Exit mysql

mysql> exit

Should return “Bye” Next log in as root with the password “YES” option

$ mysql -u root -p

You should now be able to log into as root with the password you set.

If you like you can now run mysql_secure_installation to setup further security measures like the authorization plugin.

$ sudo mysql_secure_installation;

Please refer to this excellent article on Digitial Ocean for further reading.