-2

Its been a while since i didn't use php and get error for connection to MySQL.

What I have tried: I tried username root, empty password and gives same error, but when tried ip of actual machine it gives me is not allowed to connect to this MariaDB server.

    <?php
   $servername = "localhost";
   $username = "username";
   $password = "password";
   $dbname = "MyGuests";

   // Create connection
   $conn = new mysqli($servername, $username, $password, $dbname);
   // Check connection
   if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
   }else echo "connection sucessfull";

Other errors: In phpmyadmin localhost when i click user accounts tab it gives me #126 - index for table '.\mysql\user.MYI' is corrupt; try to repair it.

L.Fazliu
  • 3
  • 1
  • 5
  • 3
    Possible duplicate of [MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)](https://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw) – Dharman Jul 20 '19 at 18:50

1 Answers1

0

I tried username root, empty password and gives same error

So the error speaks for itself, access is denied.. Double check the privileges, is the root account allowed to connect and use that database? Make a new user account and try logging into phpMyAdmin with it, can you then access the database MyGuests?

when tried ip of actual machine it gives me is not allowed to connect to this MariaDB server

Make sure you allow a username to connect from host name 127.0.0.1 (or the IP you are connecting from, if not localhost). Check in mysql.users, you should see the host name and user. In phpmyadmin via User Accounts.

Other errors: In phpmyadmin localhost when i click user accounts tab it gives me #126 - index for table '.\mysql\user.MYI' is corrupt; try to repair it.

This might be a cause: this is where the user accounts are stored. Repairing it can be done with the query: REPAIR TABLE mysql.user

ArendE
  • 897
  • 1
  • 6
  • 13