My website issues a SQLSTATE[HY000] [1049] Unknown database 'xxxxxx' even after I have imported the database.

December 31, 2018 5.4k views
MySQL PHP Ubuntu 16.04

I am new to digital ocean, but have recently uploaded a website using the LAMP stack. The website is working fine, however I have an html form on a page that sends the data to a MySQL database. I imported the the database following this tutorial “How to Import and Export Databases in MySQL or MariaDB (https://www.digitalocean.com/community/tutorials/how-to-import-and-export-databases-in-mysql-or-mariadb)”.

When I check for the database in the MySQL interface in terminal through “SHOW DATABASES;”, I see that the database has been imported. I checked phpmyadmin and see that the tables have all been correctly configured. The error still occurs and it seems like my website/droplet is still unknown issuing the SQLSTATE[HY000] [1049] Unknown database ‘xxxxxx’ error.

I use a PHP connection via PDO if that helps.

1 Answer

Are you certain the database mentioned in the error line ‘xxxxxx’ exists? Meaning make sure this DB ('xxxxxx’) isn’t the name of the old DB on the old server. If that’s the case, try logging in to the DB from the command line using the 'mysql’ binary like this:

mysql -u db_user -p db_name

Cheers

  • Thanks for replying! When I typed

    mysql -u db_user -p db_name
    

    I got the following output:

    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is xxx
    Server version: 5.7.24-0ubuntu0.16.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    

    So it doesn’t show it there, but when I type SHOW DATABASES; the database in question is displayed.

    • Check the full values used by the application to connect to the MySQL server. This error won’t be the result of the application making a mistake, but the application connecting to a MySQL server without access to that database. Consider all values individually and make sure that they do what you expect. The main variables for connecting to a MySQL server will be host, user, pass, and database.

Have another answer? Share your knowledge.