Support » Localhost Installs » LAMP – Ubuntu 20.04 – Can’t select database

  • Resolved Jan


    These are the steps I followed to install a WordPress locally:
    I followed these instructions from STEP 4 as I already had the lamp stack installed.

    Creating the Apache Server blocks I used this:

    <VirtualHost *:80>
      ServerAdmin jan@localhost
      DocumentRoot /var/www/html/wordpress/wordpress01/
      ServerName wordpress01
      ServerAlias wordpress01
      <Directory /var/www/html/wordpress/wordpress01/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined

    After all was said and done I updated my wp-config.php with this:

    /** The name of the database for WordPress */
    define( 'DB_NAME', 'wordpress01' );
    /** MySQL database username */
    define( 'DB_USER', 'jan@localhost' );
    /** MySQL database password */
    define( 'DB_PASSWORD', 'password' );
    /** MySQL hostname */
    define( 'DB_HOST', 'localhost' );
    /** Database Charset to use in creating database tables. */
    define( 'DB_CHARSET', 'utf8' );
    /** The Database Collate type. Don't change this if in doubt. */
    define( 'DB_COLLATE', '' );

    And then got the Authentication Unique Keys and Salts and updated those.

    $table_prefix = 'wp_';

    And then I get this result:

    Access denied for user ‘jan@localhost’@’%’ to database ‘wordpress01’

    Can’t select database
    We were able to connect to the database server (which means your username and password is okay) but not able to select the wordpress01 database.

    Are you sure it exists?
    Does the user jan@localhost have permission to use the wordpress01 database?
    On some systems the name of your database is prefixed with your username, so it would be like username_wordpress01. Could that be the problem?

    I am sure I have taken a wrong turn somewhere, or left something out but I can’t see where.


Viewing 5 replies - 1 through 5 (of 5 total)
  • Does the user jan@localhost have permission to use the wordpress01 database?

    Have you confirmed this?

    If you suspect WordPress might be “misbehaving”, you can always test a direct connection to the database. If it succeeds, then you know the problem is with WordPress and not your database or credentials.

    Connecting from the command line:

    Connecting from a simple PHP script:

    Good luck!

    Thread Starter Jan


    I don’t know how to confirm this: I did do the setup like this:

    CREATE USER 'jan'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON wordpress01.* TO 'jan'@'localhost';

    I used this from your one link: mysql -u jan@lochost -p password -h localhost wordpress01

    Variables (--variable-name=value)
    and boolean options {FALSE|TRUE}  Value (after reading options)
    --------------------------------- ----------------------------------------
    auto-rehash                       TRUE
    auto-vertical-output              FALSE
    bind-address                      (No default value)
    binary-as-hex                     FALSE
    character-sets-dir                (No default value)
    column-type-info                  FALSE
    comments                          FALSE
    compress                          FALSE
    database                          (No default value)
    default-character-set             auto
    delimiter                         ;
    enable-cleartext-plugin           FALSE
    vertical                          FALSE
    force                             FALSE
    histignore                        (No default value)
    named-commands                    FALSE
    ignore-spaces                     FALSE
    init-command                      (No default value)
    local-infile                      FALSE
    no-beep                           FALSE
    host                              localhost
    dns-srv-name                      (No default value)
    html                              FALSE
    xml                               FALSE
    line-numbers                      TRUE
    unbuffered                        FALSE
    column-names                      TRUE
    sigint-ignore                     FALSE
    port                              0
    prompt                            mysql> 
    quick                             FALSE
    raw                               FALSE
    reconnect                         TRUE
    socket                            (No default value)
    server-public-key-path            (No default value)
    get-server-public-key             FALSE
    ssl-ca                            (No default value)
    ssl-capath                        (No default value)
    ssl-cert                          (No default value)
    ssl-cipher                        (No default value)
    ssl-key                           (No default value)
    ssl-crl                           (No default value)
    ssl-crlpath                       (No default value)
    tls-version                       (No default value)
    tls-ciphersuites                  (No default value)
    table                             FALSE
    <strong>user                              jan@lochost</strong>
    safe-updates                      FALSE
    i-am-a-dummy                      FALSE
    connect-timeout                   0
    max-allowed-packet                16777216
    net-buffer-length                 16384
    select-limit                      1000
    max-join-size                     1000000
    show-warnings                     FALSE
    plugin-dir                        (No default value)
    default-auth                      (No default value)
    binary-mode                       FALSE
    connect-expired-password          FALSE
    network-namespace                 (No default value)
    compression-algorithms            (No default value)
    zstd-compression-level            3
    load-data-local-dir               (No default value)

    I don’t know what to look for here?

    And then I don’t know what to do with

    Thread Starter Jan


    I saw now that there isn’t a database connected.

    I already started the starting from scratch process.

    Let us see if I can get it right this time.



    May I offer some tips:
    – the package: phpmyadmin
    is almost essential, it gives you a gui browser view into your mysql setup, configuration, databases and all. It will for instance show you if your database exists, what tables and contents it has etc.
    – you are using the same name “wordpress01” for both your database and WordPress directory, this could lead to unfortunate confusion.

    Thread Starter Jan


    @rossmitchell Thanks!

    I resolved this with a different set of instructions.
    And just adjusted as I found errors.

    I installed phpmyadmin – I’ll most def use that in the future.

    I ended up just installing one local wordpress site and I’ll check on the database and directory names now.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.