简体   繁体   中英

Xampp Access Denied phpmyadmin not connecting to MySQL

I read a lot of similar questions but nowhere did I find a definitive answer. Also my issue is different from those because until I shut down my system literally an hour back everything was working fine. So I'm posting my issue again in a separate question.

I'm running Xampp on Linux(Ubuntu 14.04) and while everything was working fine until an hour back right after I shut it down it suddenly starts throwing this error. I have not changed a single line of code in any file or changed any permissions or run any unknown command in Linux whatsoever :

Connection failed: SQLSTATE[HY000] [1049] Unknown database 'user_list'

Notice: Undefined variable: connect in /opt/lampp/htdocs/Project1_July2015/verify_blacklisted.php on line 15

Fatal error: Call to a member function prepare() on null in /opt/lampp/htdocs/Project1_July2015/verify_blacklisted.php on line 15

I have tested PDO connections using the variable 'connect' that connects to my database 'user_list' which DOES exist. It DOES retrieve data correctly. When I try to connect to localhost/phpmyadmin

MySQL said: 

Cannot connect: invalid settings. 
Connection for controluser as defined in your configuration failed.
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

The username hasn't been set. It's "root" and password hasn't been set. I've been working with the same setting without changing any ownership or any other details in the installation of Xampp. I have no clue as to why this is happening. Anyone with any experience in this area that can help me solve these issues?

Edit : On further testing, I can connect to my other website on localhost that is stored similar to this one in my htdocs folder so it is definitely a problem only related to phpmyadmin not connecting to my databases because the website that works doesn't involve connection to any databases on it's home page at least. Just mentioned it in case that detail helps in solving the issue.

My connection code is as follows and it worked right until an hour back :

<?php
    $server_name = "127.0.0.1";
    $server_username = "root";
    $server_password = "";
    $db_name=$_SESSION["db_name"];

    //echo "<br>"."Attempting connection to database " . $db_name . "<br>";
    try {
        $connect = new PDO("mysql:host=$server_name;dbname=$db_name", $server_username, $server_password);

        $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        //echo "<br>"."Connected successfully to database " . $db_name . "<br>"; 
    } catch(PDOException $e) {
        echo "<br>" . "Connection failed: " . $e->getMessage() . "<br>";
    }
    //#3
?>

Edit 2 : Like I said the code is fine. I haven't changed a single line of it and it worked perfectly before as well. My main issue here is that phpmyadmin itself cannot connect to the databases. Refer the screenshot below for details. I think that is the root cause of all the other issues :

在此处输入图片说明

So turns out the issue is a double installation of mysql within xampp as well as separately and handling which version is currently running.

This is what helped me figure it out

https://apple.stackexchange.com/questions/69955/how-to-stop-xampp-mysql-server

And this is a manual method I figured out later if it helps :

Installing xampp but phpmyadmin doesn't connect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM