Symptoms

Accessing the site's URL does not result in a page or a redirect to the installer, but you are greeted by this error instead:

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table '[database].semaphore' doesn't exist: SELECT expire, value FROM {semaphore} WHERE name = :name; Array ( [:name] => variable_init ) in lock_may_be_available() (line 164 of C:\www\core7\includes\lock.inc).

Causes & Solutions

The ultimate source of this error is that the table semaphore doesn't exist in the database.

Manually edited settings.php before running the installer

Adding the database data to settings.php makes Drupal "believe" it is already installed.

Solution: Do not edit settings.php manually; please follow the steps in INSTALL.txt.

In most cases you cannot rescue the install by visiting install.php, as the installation will now abort with the error

Table variable already exists.

To solve this, discard your manually edited settings.php file, empty the database, then follow the steps in INSTALL.txt.

The database has been emptied or the table semaphore has been removed

Solution: Restore the database from backup.

Comments

mhamed’s picture

the error was caused by the settings.php that i created

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbName_semaphore' doesn't exist: SELECT expire, value FROM {semaphore} WHERE name = :name; Array ( [:name] => variable_init ) in lock_may_be_available() (line 167 of /home/user/public_html/includes/lock.inc).
I deleted it
Refreshed and the installation process started
the installation auto-created the settings.php

tkittich’s picture

I ran into the same error. I am using Acquia Dev Desktop and imported a site to a dev machine as localhost7 to be accessed locally as http://localhost7. Somehow in drupal "sites" directory i got both "default" and "localhost7" directories containing the same set of files. And that confuses drupal. Once I removed "sites/localhost7" this issue is gone. ^^

rwilson0429’s picture

I experienced this error after running a script to remove database table prefixes. I fixed it by rerunning the Drupal install script. I simply remove the original settings.php file and copied the default.settings.php into my sites/default folder as settings.php. Then I visited the site, this caused the install script to run. When prompted for my database settings, I entered the name of my existing database. The install script will inform you that the database already exists and offer to take you to your site.

ReggieW

Webcleric’s picture

@rwilson0429
That helped me, thank you :)

ninobrownh20’s picture

This solved my problem. Ty.

manumad40’s picture

I solved this error assigning correct permissions on a multisite D7 with the "chmod" command to my downloaded files:

  • Permission 755 to all directories and subdirectories.
  • Permission 644 to all files into it.
  • And checking that the user:group is OK in all cases, changing it with the command "chown -R" if necessary.

The subdirectories and files into the "sites/[your_site_name]/files" directory could contain other permissions:

  • 555 or 755 or 775 should be OK for all its subdirectories. Very important: "sites/[your_site_name]/files" subdirectory will be always 775 to allow the system writing temporary and uploaded files.
  • 664 or 644 to all files inside them.

If you are also running a multisite installation with your sites distributed into different virtual hosts or hosting accounts (i.e.: cPanel/WHM accounts), you will need to run a copy of all the downloaded common Drupal files to every single site. Linking these files from one vhost to another will break your installation. The "sites" directory should be the only different structure into each vhost site. Of course, you can use a different database and user for each vhost site.

Christopher James Francis Rodgers’s picture

Re: Drupal 7 - Download existing online-webhost site
originally created/maintained by webhost's
free Control-Panel 'automated script service', SimpleScripts;

& Now I am trying to run it locally on my computer
using 'Acquia Dev Desktop'.

===

[Error: (partial)]

PDOException: SQLSTATE[42S02] PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table ... semaphore' doesn't exist

===

[Solution]

In my case, all I had to do was add the line
'prefix' => 'dr_',
to the bottom of the new settings.php file
inside of the new folder created by Acquia Dev Desktop.

That new folder is in [d7-root]/sites/
along with the folders "all" and "default".

[Drupal-7-root]/sites/NEW-ADCP-CREATED-FOLDER/settings.php

 

Before

///////////////////////////////////////////////////////////////////////
//       Please don't edit anything between <@@ADCP_CONF@@> tags     //
// This section is autogenerated by Acquia Dev Desktop Control Panel //
///////////////////////////////////////////////////////////////////////
//<@@ADCP_CONF@@>
$base_url = 'http://toltec1:8082';

//D6 DB config
$db_url = 'mysqli://drupaluser@127.0.0.1:33066/toltec1db';

//D7 DB config
$databases = array('default' => array('default' => array(
    'driver' => 'mysql',
    'database' => 'toltec1db',
    'username' => 'drupaluser',
    'password' => '',
    'host' => '127.0.0.1',
    'port' => 33066 )));
//</@@ADCP_CONF@@>

 

After - Add:
'prefix' => 'dr_',

///////////////////////////////////////////////////////////////////////
//       Please don't edit anything between <@@ADCP_CONF@@> tags     //
// This section is autogenerated by Acquia Dev Desktop Control Panel //
///////////////////////////////////////////////////////////////////////
//<@@ADCP_CONF@@>
$base_url = 'http://toltec1:8082';

//D6 DB config
$db_url = 'mysqli://drupaluser@127.0.0.1:33066/toltec1db';

//D7 DB config
$databases = array('default' => array('default' => array(
    'prefix' => 'dr_',
    'driver' => 'mysql',
    'database' => 'toltec1db',
    'username' => 'drupaluser',
    'password' => '',
    'host' => '127.0.0.1',
    'port' => 33066 )));
//</@@ADCP_CONF@@>

 

The sites I imported into ADCP (Acquia Dev Desktop Control Panel)
that were giving me the error,
were all sites I had exported from my webhost,
but they were also sites that I originally created
using the webhost's Control Panel free scripting service,
SimpleScripts.

I believe that is how the prefix 'dr_' got involved.

Still, other Drupal websites exported from my online webhost
did install into ADCP perfectly;
but, those were web sites that I manually installed
at my webhost.

Now, I know what to do.

===

After I have downloaded my 'folders/files codebase',
and my 'database dump file' (*.sql) from my webhost,
I 'Import' each website into ADCP.

If on my first attempt to visit my site,
I see the above mentioned error,
then I check that site's old settings.php files:

Old settings.php
[Drupal-7-root]/sites/default/settings.php

If I see the code
'prefix' => 'dr_',
existing in the old settings.php file,
then I add that bit of code to the the bottom
of the new setting.php file
created by a ADCP 'Import':

New: settings.php
[Drupal-7-root]/sites/NEW-ADCP-CREATED-FOLDER/settings.php

~~~ The End. ~~~

 

===

For help Installing and setting up Acquia Dev Desktop on Windows PC; or MAC

I do recommend the page:

Drupal 7 (or 6) - Install and Setup Acquia Dev Desktop (Formerly DAMP) on your Windows PC or MAC - Video with outline

=== Reference ===

Error

The website encountered an unexpected error. Please try again later.

Error message

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'wbidb.semaphore' doesn't exist: SELECT expire, value FROM {semaphore} WHERE name = :name; Array ( [:name] => variable_init ) in lock_may_be_available() (line 167 of C:\zzr\ggm\tmp\2014.01.06-d7.24-for_testing-damp_deleting\drp3--webbldi\website-building-information\includes\lock.inc).

Uncaught exception thrown in shutdown function.

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'wbidb.semaphore' doesn't exist: DELETE FROM {semaphore} WHERE (value = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => 56604783252cacebf8652c8.32192761 ) in lock_release_all() (line 269 of C:\zzr\ggm\tmp\2014.01.06-d7.24-for_testing-damp_deleting\drp3--webbldi\website-building-information\includes\lock.inc).

===


All the best; intended.
-Chris (great-grandpa.com)
___
"The number one stated objective for Drupal is improving usability." ~Dries Buytaert *

gchalker@princeton.edu’s picture

If you were standing before me, I would stand right up and kiss you!

I've been trying to solve this problem all night, with this, with that, all sorts of things for 4 hours now. Until, I ran into your solution!

Adding a simple 'prefix' => 'dr_',

along with your before and after example saved the day!

Thank you so much.

DesignerChix

karolus’s picture

Chris--
Thanks for finding the issue--it was a real hassle to figure out before I found this post.

Instead of modifying the Dev Desktop file, though (I tried and it didn't seem to work for me), was to go into phpMyAdmin via Dev Desktop once the DB dump was imported was to select all tables and edit the prefix to be blank (there is a select to do this). Once this was done, things were good to go.

justin.wheeler’s picture

Yes! After days of googling and trying stuff that is apparently outdated this clued me in. Just to spell this out and dumb it down even further - in my case the prefix wasn't dr_ but something else. I originally setup my site on our hosting provider using Softaculous installer, which assigned the prefix of drpb_ to every table in my SQL file.

When I transferred to a new hosting account I manually setup a clean drupal install, then imported my database. Well, doing so created a settings.php file without ANY prefix. My settings.php was looking for tables but essentially had the right city and house number, but the wrong street.

1 - login to phpMyAdmin and find your database
2 - expand the tree and see if there is a prefix in front of your tables. If all of your tables start with xyz_ for example - that's your prefix
3 - Open your settings.php file for editing under sites > default (you may need to open permissions on both the 'default' folder and the 'settings.php' file to make them writeable.
4 - find the prefix line under your database and username info and enter the correct prefix:

$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'xxx_xxx',
'username' => 'xxx_xxx',
'password' => 'xxxxxxx',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => 'xyz_',
),
),
);

5 - login to site and flush caches
6 - run cron
7 - run updates

Note: after I did all of this I got my site **mostly** back, but there's still something I'm missing. The template is now correct but all of my blocks and views are gone. Luckily I wasn't too deep into developing the site, but it will still be hours of work to get this back to where it was before the move and I'm not sure what I missed.

brandonc503’s picture

im using copy of my site files and database dump in Aquia DevDesktop and getting this ..
http://i.imgur.com/uSgLINQ.png
i used someone elses d6 files and db dump and worked perfect. I know thats a big difference but thougth id inlude it. also the Semephore table does exist in source and cloned db. both empty tables.

Vishambar’s picture

Hi all i am facing below error in durpal 7 during modifying data.

DOException: SQLSTATE[42S02]: Base table or view not found: 1146 La table 'vui.cache_block' n'existe pas: DELETE FROM {cache_block} WHERE (expire <> :db_condition_placeholder_0) AND (expire < :db_condition_placeholder_1) ; Array ( [:db_condition_placeholder_0] => 0 [:db_condition_placeholder_1] => 1447488989 ) in cache_clear_all() (line 168 of F:\wamp\www\Ventures\includes\cache.inc).

I have tried to add 'prefix' => 'dr_', in setting.php yet error occurring.

frederickjh’s picture

I ran into this same PDOException: SQLSTATE[42S02]: . . . error message in moving Drupal 7 from one development site to another development site on my laptop. Upon checking the tables in the Drupal database I found that the full sql dump was not being imported (using Adminer and the "From server" option, adminer.sql). The last table it imported was the locales_target table.

Link to image of partial sql dump import

Look for Drupal 7 database tables that come near the end of the dump alphabetically like: user*, views*, webform*, workbench*, xmlsitemap* to see if it all imported.

I then used drush sql-cli < database.sql to import the sql dump into the Drupal database after dropping all tables with drush sql-drop.

Link to image of sql dump import that finished

Note: I am linking to the images instead of putting them inline as only images on drupal.org are allowed and there is no way to upload images on these comments.

debrajmandal2007’s picture

I have developed the project in localhost and it is working properly. I moved the project to live server and database also. After running the project 'db connection error' was came. But I changed the settings.php file with live config and upload it. Then the following error came : --

Skip to main content
Error
The website encountered an unexpected error. Please try again later.
Error message
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ITConsultingWebSolutions17.semaphore' doesn't exist: SELECT expire, value FROM {semaphore} WHERE name = :name; Array ( [:name] => variable_init ) in lock_may_be_available() (line 167 of /home/itconsul/public_html/includes/lock.inc).
Uncaught exception thrown in shutdown function.

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ITConsultingWebSolutions17.semaphore' doesn't exist: DELETE FROM {semaphore} WHERE (value = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => 7214980795aaf63fb62f344.24662330 ) in lock_release_all() (line 269 of /home/itconsul/public_html/includes/lock.inc).

Then I changed the file permission of sites folder and sub folder permissions to 0755. I think this is coming due to any permission problem. I do not have any db tables prefix. Please tell me the file permission structure for sites folder for live sites. I am using Linux server with mysql database.

Thanks
Debraj Mandal

renemayeaux’s picture

I was able to clear the problem with changing the file permissions to 777 because my prior file permissions were 755 but I also got a Ajax 500 error during the install but was able to press the webpage reset twice during the install and the install did continue and finish. I would not have know about the webpage reset as it isn't listed as a repair or fix anywhere... Hope this helps someone...

wkerckhove’s picture

When I run cron, I get the following message:
Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ID9999_db2.semaphore' doesn't exist in /data/sites/web/....../www/includes/database/database.inc:2227 Stack trace: #0 /data/sites/web/......./www/includes/database/database.inc(2227): PDOStatement->execute(Array) #1 /data/sites/web/........../www/includes/database/database.inc(697): DatabaseStatementBase->execute(Array, Array) #2 /data/sites/web/......./www/includes/database/database.inc(2406): DatabaseConnection->query('SELECT expire, ...', Array, Array) #3 /data/sites/web/....../www/includes/lock.inc(167): db_query('SELECT expire, ...', Array) #4 /data/sites/web/......../www/includes/lock.inc(146): lock_may_be_available('schema:runtime:...') #5 /data/sites/web/......./www/includes/bootstrap.inc(438): lock_acquire('schema:runtime:...') #6 /data/sites/web/vrijwilligersrabbe/www/includes/bootstrap.inc(460): DrupalCacheArray->set(Array) #7 [internal funct in /data/sites/web/...../www/includes/database/database.inc on line 2227

I have the following configuration in the settings.php:

$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'ID9999_drupal',
'username' =>
'password' =>
'host' =>
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),

'rab_db' =>
array (
'default' =>
array (
'database' => 'ID9999_databas',
'username' =>
'password' =>
'host' =>
'port' =>
'driver' => 'mysql',
'prefix' => '',
),
),

'rab_db2' =>
array (
'default' =>
array (
'database' => 'ID9999_db2',
'username' =>,
'password' =>
'host' =>
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),

In fact, the table semaphore is in ID9999_drupal which is the "default" database.

The semaphore table was set, but why is the system checking if there is a searching for a semaphore in the second additional database ID9999_db?

Similar "double" queries occur for flood, cache_update, cache and queue.

Why and how can I solve this?

Regards

serverjohn’s picture

This did it for me I missed the prefix

wkerckhove’s picture

Yes, I have read this. But I am running my site already for more than 10 years. The basic structure hasn't changed. This suddenly happened a few months ago, but I don't know when and how. I have been cleaning up the system, The ID9999_drupal contains all and only the the system. ID9999_ds2 , ID9999_database and more (not shown) contain only data, only updatdd once a month.

someshver’s picture

Run update.php solved my issue.

huijse’s picture

I solved this by doing the import in the mysql db GUI in my case Adminer ( but could have been Phpadmin too)

Drush did probably not fully import the database. It took a very short time for a big db. Than the error mentioned above occurred.
(perhaps there was a broken db loaded)
I saw in

drush status

the database was not connected.
So I tried to import it in another manner and this solved it for me.