1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

MySQL Not Working: "mysqli_connect(): Access denied for user 'root'@'localhost'"

Discussion in 'Help' started by LyricalLyfes, Feb 21, 2021.

  1. LyricalLyfes

    LyricalLyfes Spider Jockey

    Messages:
    28
    So I bought a new VPS for first time and tried to connect mysql database to it and whenever I run the server it gives me this error "mysqli_connect(): Access denied for user 'root'@'localhost'" I've been trying all day to get it fixed but can't seem to find a way Here's the code:

    public function onEnable()
    {
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $this->getLogger()->info("BowCommand Enabled");
    $dbServerName = "127.0.0.1";
    $dbUsername = "root";
    $dbPassword = "MyPassword";
    $dbName = "minecraft";
    $conn = mysqli_connect($dbServerName, $dbUsername, $dbPassword, $dbName);
    echo "worked";


    }
     
  2. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    I think is work
    PHP:

    $mysql 
    = new \mysqli($dbServerName$dbUsername$dbPassword$dbName);
    if(
    $mysql->connect()){
    $this->getLogger()->info("Mysql Can connect");
    }else{
    $this->getLogger()->info("Mysql Can't connect");
    }
     
  3. Primus

    Primus Zombie Pigman

    Messages:
    749
    Apparently there is something wrong with your setup. Can you connect to your localhost using same credentials from elsewhere?

    This question is already answered, many times and has nothing to do with the pocketmine nor with php itself.

    https://stackoverflow.com/questions...y000-1045-access-denied-for-user-usernameloca
     
  4. LyricalLyfes

    LyricalLyfes Spider Jockey

    Messages:
    28
    Yeah. I’ve tried to login from the terminal multiple times and it works but when I try using it with php it just doesn’t work
     
  5. LyricalLyfes

    LyricalLyfes Spider Jockey

    Messages:
    28
    Also, I’m not sure if I should put my VPS ip instead of local host but when I do it says “Connection refused”
     
  6. Primus

    Primus Zombie Pigman

    Messages:
    749
    Localhost refers to the local network on which the software is running.

    From what I understand is that your mysql server is on the VPS. So if you'd like to connect to it, while referring to localhost, then the plugin must be running on the VPS. And if you're trying to connect to it while outside of it, i.e. your computer (by definition its remote connection), then the port must be open and mysql server configured to accept/authorize/handle such connections. Read this article if that is the case: https://phoenixnap.com/kb/mysql-remote-connection
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.