• I’m setting up a brand new local WordPress site on my laptop as a local development server. I created a database and started the installer by navigating to ‘localhost’. On page 2 I got an error:

    “We were able to connect to the database server (which means your username and password is okay) but not able to select the database.”

    I was connecting as root when I got that error.

    So, I tried creating a new user and assigning that user to the database in phpMyAdmin. It seemed successful, but when I tried the install again using the new user, I got the

    “Error establishing a database connection”

    That others have mentioned.

    What is going on here?

    Here are the pertinent details i have:

    Installing on Windows 7 guest host in VirtualBox in WAMPServer 3.2.

    Here are some question I can anticipate that I’m addressing up-front:

    Q & A:

    1) Did you try reinstalling the WampServer?
    No. I JUST installed it on a fresh Virtual machine on a brand new laptop that had nothing but Windows 10 on it. It doesn’t make sense that WampServer would get corrupted so early (directly after ‘birth’) in its lifecycle.

    2) Did you try manually creating a wp-config file?
    Actually, yes I did. Here is the order things went:
    a) Tried 5-minute install as root, but failed at page 2 after entering the database connect details. Result: Error – Able to connect to database server just fine, but unable to SELECT database.
    b) Tried 5-minute install again after manually creating wp-config file, but duplicating wp-config-sample.php and changing the database connection details. Result: Error – Unable to connect to database.
    c) Delete wp-config file and tried 5-minute install again with a newly created user (not root), after assigning all privleges to the user. Result – Error – Error establishing a database connection (again).

    3) Did you try contacting your ISP?
    That wouldn’t make sense since I suppose I am my own ISP since I’m on localhost.

    I’ve done my best to provide all the details you might need.

    Questions:

    What is causing this and how do I fix it?

    I won’t be offended by detail — the more detail the better!

    Any help is appreciated.

    • This topic was modified 4 years, 8 months ago by James Huff. Reason: moved to Localhost Installs since this is a localhost install
Viewing 11 replies - 1 through 11 (of 11 total)
  • Just off the top of my head :
    Open your config file, to verify the user.
    Open your phpMyAdmin –> Users on that database and verify that the user has the right access.
    Open a command prompt and connect to that db using mysql :
    https://www.a2hosting.com/kb/developer-corner/mysql/connect-to-mysql-from-the-command-line
    Check your hosts file and make sure you have access :
    https://john-dugan.com/wamp-vhost-setup/
    Check your conf file, or your htaccess file, or your AV settings to make sure that the user is not under a <deny> directive.

    Thread Starter Eric Hepperle

    (@codeslayer2010)

    Thanks @corrinarusso. I will give those tips a try and report back….

    OK. Here are my findings:

    1) Open your config file, to verify the user.
    A: In case it wasn’t clear in from the description, I don’t actually have a wp-config.php file yet because WordPress failed to complete the install. It keeps failing at page 2 (as indicated above).

    2) Open your phpMyAdmin –> Users on that database and verify that the user has the right access.
    A: My root user has all privileges granted.

    3) Open a command prompt and connect to that db using mysql :
    https://www.a2hosting.com/kb/developer-corner/mysql/connect-to-mysql-from-the-command-line
    A: Root can successfully connect to the database via the MySql console (though it is empty and has not structure yet) just fine. Specifically, I mean the ‘use [MYDATABASE]’ command results in “Database changed”.

    4) Check your hosts file and make sure you have access :
    https://john-dugan.com/wamp-vhost-setup/
    A: I don’t understand what you are asking here. I went to the link, but he only demonstrated part of the process, and left out the hows and whys of setting up a vhost.

    5) Check your conf file, or your htaccess file, or your AV settings to make sure that the user is not under a <deny> directive.
    A: I am not sure what you are asking here. Can you please provide more detail? Here is the entire contents of my httpd-vhosts-conf file:

    # Virtual Hosts
    #
    <VirtualHost *:80>
    ServerName localhost
    ServerAlias localhost
    DocumentRoot “${INSTALL_DIR}/www”
    <Directory “${INSTALL_DIR}/www/”>
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
    </Directory>
    </VirtualHost>

    I’m not seeing anything that looks like a deny directive.

    Thanks again for your help so far. This has been so frustrating because I should be able to install WordPress on a brand new laptop, as there is the least possiblity of issues like viruses, malware, corrupt configurations, etc. This just doesn’t make any sense why WordPress won’t install.

    • This reply was modified 4 years, 8 months ago by Eric Hepperle. Reason: updated
    • This reply was modified 4 years, 8 months ago by Eric Hepperle. Reason: clarifications
    Thread Starter Eric Hepperle

    (@codeslayer2010)

    My issues is detailed and clearly laid out … can’t anyone help where @corrinarusso left off?

    And how do I report #postVandalism? Somebody removed all five relevant tags I posted this question with.

    • This reply was modified 4 years, 8 months ago by Eric Hepperle.

    Hi @codeslayer2010

    This does not make sense :
    > I don’t actually have a wp-config.php file yet because WordPress failed to complete the install.
    The config file is not generated before install.
    The config file is extracted from the tar :
    https://www.ads-software.com/download/
    and then it auto-fills when you run the installer :
    https://i0.wp.com/www.ads-software.com/support/files/2018/10/install-step3_v47.png

    However, nothing prevents you from filling in the config file on your own using a text editor.

    WordPress failing to install on your local machine is not the same as not having a wp-config.php file at your root :
    > DocumentRoot “${INSTALL_DIR}/www

    This error message tells me that your WordPress tar file has been extracted properly :
    > Error establishing a database connection
    So go to your root under www and open the wp-config.php file, and make sure the parameters in there are correct, specifically these entries :
    define( ‘DB_NAME’, ‘you-database-name’ );
    /** MySQL database username */
    define( ‘DB_USER’, ‘root’ );
    /** MySQL database password */
    define( ‘DB_PASSWORD’, ” ); // are you using root –> no password? If so, leave this blank
    /** MySQL hostname */
    define( ‘DB_HOST’, ‘localhost’ );

    > And how do I report #postVandalism
    Don’t worry about it.

    Thread Starter Eric Hepperle

    (@codeslayer2010)

    Thank you for your reply Corrina. Let me try to address your comments:

    TL;DR —> Skip to the bottom for summary and conclusion. On the other hand, if you want to be fully informed begin reading below.

    > This does not make sense :
    > > I don’t actually have a wp-config.php file yet because WordPress failed to complete the install.
    > The config file is not generated before install.
    >
    > The config file is extracted from the tar :
    > https://www.ads-software.com/download/
    > and then it auto-fills when you run the installer :
    > https://i0.wp.com/www.ads-software.com/support/files/2018/10/install-step3_v47.png
    >
    > However, nothing prevents you from filling in the config file on your own using a text editor.

    That’s not exactly correct. I have installed over 30 WordPress websites during the last 6 years (including 18 on localhost) and although you can create your own wp-config file before starting the install, the installer always asks if you would like it (the installer) to create a wp-config.php file (“Create a Configuration File”) for you, as in this video at 9:06 from 2014:

    May of 2019 was the last time (before about a month ago) that I installed a WordPress website. I’ve only been out of the loop for about a year. Has WordPress changed so drastically since a year ago, … such that it no longer works like that?

    > WordPress failing to install on your local machine is not the same as not having a wp-config.php file at your root :
    > > DocumentRoot “${INSTALL_DIR}/www
    Yes, that seems accurate.

    > This error message tells me that your WordPress tar file has been extracted properly :
    > > Error establishing a database connection
    > So go to your root under www and open the wp-config.php file, and make sure the parameters in there are correct, specifically these entries :
    > define( ‘DB_NAME’, ‘you-database-name’ );
    > /** MySQL database username */
    > define( ‘DB_USER’, ‘root’ );
    > /** MySQL database password */
    > define( ‘DB_PASSWORD’, ” ); // are you using root –> no password? If so, leave this blank
    > /** MySQL hostname */
    > define( ‘DB_HOST’, ‘localhost’ );
    Like I said, the installer didn’t autocreate the wp-config.php file like it was supposed to.

    But, I wanted to give your advice a fair shake, so I uninstalled WampServer today and WordPress and started over from scratch. After rebooting my Windows 7 machine, I re-installed WampServer successfully (as before). The only issue was that a couple of the dependencies WampServer seemed to require couldn’t be found. I couldn’t find them on the WampServer website where all the other VC redistrubutables were.

    > VC_2013_REDIST_X86_MIN ID={8122DAB1-ED4D-3676-BB0A-CA368196543E}
    > Visual C++ 2013 x86 Minimum Runtime – 12.0.40664
    > **** NOT INSTALLED ****
    > Installation file is on: https://wampserver.aviatechno.net
    > VC 2013 Package Up 5 (x86)
    > —————————————-
    > VC_2013_REDIST_X64_MIN ID={53CF6934-A98D-3D84-9146-FC4EDF3D5641}
    > Visual C++ 2013 x64 Minimum Runtime Update 5 – 12.0.40664
    > **** NOT INSTALLED ****
    > Installation file is on: https://wampserver.aviatechno.net
    > VC 2013 Up 5 (x64)
    > —————————————-

    I searched online also and could not find these particular redistrubutable packages. So, I determined (as before) to go on with the install of WampServer and happily didn’t receive any error messages and it seemed to complete the install successfully.

    I then attempted to install WordPress again.

    I unzipped the ZIP file (not a tar) into WampServer’s www folder, and as before there was no wp-config file, only a wp-config-sample.php. I opened phpMyAdmin and successfully created a database. Here is where I changed my process. I follower your instructions by duplicating the wp-config-sample.php file and renaming the duplicate “wp-config.php”. Then I edited the database (DB) connection details as follows:

    > // ** MySQL settings – You can get this info from your web host ** //
    > /** The name of the database for WordPress */
    > define( ‘DB_NAME’, ‘ehw_20200712_01’ );
    >
    > /** MySQL database username */
    > define( ‘DB_USER’, ‘root’ );
    >
    > /** MySQL database password */
    > define( ‘DB_PASSWORD’, ” );
    >
    > /** MySQL hostname */
    > define( ‘DB_HOST’, ‘localhost’ );
    >
    > /** Database Charset to use in creating database tables. */
    > define( ‘DB_CHARSET’, ‘utf8mb4’ );
    >
    > /** The Database Collate type. Don’t change this if in doubt. */
    > define( ‘DB_COLLATE’, ” );

    One interesting point to note: There was no variable in the sample file to define the “wp_” prefix. Could that be the problem?

    Also in the sample file, the default charset was “utf8”, while the default charset in phpMyAdmin is “utf8mb4”. Could that cause the failure to connect issue?

    NOTE: I changed “utf8” in the variables to “utf8mb4” while troubleshooting, but it didn’t make a difference.

    The installer now ( ) says this:

    “The file wp-config.php already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now.”

    I clicked the “installing now” hyperlink and got this ERROR:

    “Can’t select database”

    with all the boiler plate I detailed in my original post on this thread.

    CONCLUSION:

    I tried your suggestions but I’m still having the same problem. This is a simple process … why is it breaking on something so simple all of a sudden??

    > > And how do I report #postVandalism
    > Don’t worry about it.

    Huh? What do you mean? That doesn’t make any sense. When someone (or something) destroys or removes my work/contributions without warning or explanation I have a right to be concerned. My tags add context and help others who may have the same issue discover my post that may help them in their research. This is a community and we are all here to help each other. It goes without saying, but the tags are designed to help those searching for anwers.

    So it doesn’t make sense that my tags would just up and disappear. Either a moderator deleted them (on purpose, or by accident), or community users, or a bot/automated software program. Even if I think the reason isn’t fair, I at least deserve to know what the reason is. Any reasonable person would expect this courtesy.

    For reference, in researching my database issue, I have noticed that other recent posts are also missing tags. I have no way of knowing if that is because they were deleted or because the OP never attached any tags. But still, I find that curious, as I believe any perceptive mind would.

    ==================================

    RESULTS/CONCLUSION:

    I reinstalled everything from scratch and followed your (Corrina’s) advice to create the wp-config.php file before doing the install, populated the config file with correct database connection variables, but WordPress still won’t install and I still get the “Can’t select database” issue!

    This is very frustrating… It shouldn’t take 3 months to troubleshoot why WordPress won’t install on localhost right?

    I SUSPECT SOMETHING IS DIFFERENT IN THE NEW VERSION OF WORDPRESS INSTALLER THAN THE VERSION I SUCCESSFULLY INSTALLED FROM IN MAY OF LAST YEAR … Can you corroborate this?

    I appreciate your help so far.

    Still looking for answers. Now that we have done those steps, what would you have me do next?

    > Has WordPress changed so drastically since a year ago, … such that it no longer works like that?

    No. Nothing has changed in the process.
    Did you Grant All privileges to root on this db : ehw_20200712_01

    You can define your prefix in your config file :
    $table_prefix = ‘you_prefix_’

    > why is it breaking on something so simple all of a sudden??
    I dunno.
    Clearly you’re doing something wrong, or a config is wrong in Wamp or wp_config.

    > When someone (or something) destroys or removes my work/contributions without warning or explanation I have a right to be concerned.

    Then ask the moderator.
    I wish I had the kind of time in my life to care about why someone deleted my tags on a support forum!

    > but WordPress still won’t install and I still get the “Can’t select database” issue!

    Time to make sure your Wamp server is set up properly.
    You can also read the php error logs.

    > It shouldn’t take 3 months to troubleshoot why WordPress won’t install on localhost right?

    No!
    I use WP-CLI on my local machine, and takes 2 to 3 minutes from start to finish.

    > Now that we have done those steps, what would you have me do next?

    Time to hire a developer I guess. You can take a look here :
    https://jobs.wordpress.net/
    or here :
    https://codeable.io/

    Thread Starter Eric Hepperle

    (@codeslayer2010)

    @corrinarusso Interesting answers… I don’t think I’ll be hiring a developer anytime soon since I AM a developer. lol. I didn’t do anything wrong and I know how to follow directions.

    I may end up asking a moderator, but it’s ironic that you point out we have the exact same problem: extreme lack of time.

    No, I’m not out on somebody’s yacht too busy to work on my WordPress website. Quite the contrary, I’m at home with Chronic Fatigue Syndrome (CFS) and I’m bedridden for hours some days, others I have energy to do stuff. And well, since we aren’t fortunate enough to have a maid or any other domestic help, on the days I have free time, most of it is spent doing chores. So at the end of the day, when I use the last little bit of energy I have to jump on here and try to get some help — and usually I’ve had pretty good luck on this site — perhaps you can see from my perspective how EXTRA frustrating (as opposed to normal level frustration) it is to not be able to get this one solved.

    … Especially since (avoiding any philosophical or existential rationale) it shouldn’t be happening …

    • This reply was modified 4 years, 7 months ago by Eric Hepperle.

    Hi @codeslayer2010

    > I didn’t do anything wrong

    With all due respect, you have done *something* wrong, since it is not working.

    I think I have exhausted all the rationale to have this set up properly. Of course I don’t have access to your WAMP server, so I can’t comment on that portion.
    Again, assuming everything is setup properly on your local machine, this should take less than 5 minutes. I would strongly suspect there is nothing wrong with the WordPress install, under you didn’t managed to finish the download properly. You can certainly run a checksum from wp-cli using the verify command :
    https://www.liquidweb.com/kb/how-to-verify-wordpress-checksums-using-wp-cli/

    Hi @codeslayer2010,

    I had exactly the same issue as you’ve had.
    (Error establishing a database connection)

    I resolved this issue with simple port addition in wp-config.php file.

    /** MySQL hostname */
    //define( 'DB_HOST', '127.0.0.1' );
    define( 'DB_HOST', '127.0.0.1:3307' );

    Did it help to you?

    • This reply was modified 4 years, 3 months ago by luckybaky. Reason: displayed html tags

    I had the same problem on a new WordPress installation (yesterday) on a new MacMini using SQL 8.0 on MacOS 11.1, and on an old MacMini using SQL 5.7 on MacOS 10.13.

    Thanks to luckybaky for the non-obvious solution.

    Except I used :3306 (the standard MySQL port), and then found that the port doesn’t matter. Also, a DNS name that resolves to 127.0.0.1 also works. (“mouse-potato.com”, for example).

    “With all due respect, you have done *something* wrong, since it is not working.”

    Someone, somewhere, ain’t handling “localhost” correctly or consistently, and if all of us did something wrong, the error messages were of no help in fixing the problem in a way that is not documented anywhere I could find.

    I have been getting the same issue here and was able to resolve it by:

    Ensuring my user and my database are not the same name.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Can’t select database – Can’t install – Won’t create wp-config’ is closed to new replies.