Unable to connect to localhost database - mysql

This question has already been asked multiple times but none of the answers have helped me.
I am upgrading to Drupal 8 and to do so, I need to specify the login credentials for my Drupal 7 database.
SQLSTATE[HY000] [2002] No connection could be made because the target
machine actively refused it.
I can access the database perfectly fine to my SQL server is 100% running.
I have checked the credentials inside settings.php and it says the following:
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'karma-living.dev',
'username' => 'root',
'password' => '',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
So I copied above but I still get the error message above (yellow box).
See following image:
Does anyone have any suggestions? Thank you in advance.

The Acquia Desktop says your database name is "karma_dev", but you've entered "karma-living.dev" as the name for Drupal, so there is an inconsistency.

Related

Laravel 5: "Base table or view not found" Table X "doesn't exist" - laravel is confusing virtual hosts

Getting this error message RANDOMLY while nav'ing to my view:
QueryException in Connection.php line 636:SQLSTATE[42S02]: Base table or view not found: 1146 Table 'salesspacetv.devices' doesn't exist (SQL: select count(*) as aggregate from devices inner join statustypes on devices.status = statustypes.num inner join aggservers on devices.aggserver_num = aggservers.num left join tickets on devices.id = tickets.device_id group by devices.id) in Connection.php line 636
My server uses multiple virtual hosts, defined in c:\apache24\conf\extra\httpd-vhosts.conf.
"c1.[ourcompanyname].net" is the name of the site whose view I'm nav'ing to.
"salesspacetv.[ourcompanyname].net" is another virtual host (running laravel) on our server.
The word "salesspacetv" absolutely does not exist anywhere in c1's code.
"devices" IS a table used by the c1 site, and there is no "devices" table used by the salesspacetv site.
It seems like laravel's base code is making use somewhere of what it thinks is the subdomain name and that Apache (fyi... running on Windows, on this server) is somehow not getting the correct subdomain name to laravel.
Again, this is a random error. If I simply refresh the page, the error goes away. Also note, whether important or not, that this view is using pagination. I don't imagine that has any importance, but I figured it was worth mentioning.
The databases are MySQL databases.
Lastly, the c1 virtual host definition does actually appear before the salesspacetv virtual host definition in httpd-vhosts.conf.
Thanks.
I believe I ran into this error in the past when I was dealing with multiple projects in my local environment.
Let me get this straight, you are using 1 project then whenever it is involving a database table call it sometimes references to a table or column name that the current project does not contain but contains in another project?
If that is what's happening to you, how I fixed it on my end was name your database environments (.env file) different per project.
#1 .env Method
.env
Project 1:
DB_PROJECT1_HOST=0.0.0.0
DB_PROJECT1_DATABASE=dbname
DB_PROJECT1_USERNAME=dbuser
DB_PROJECT1_PASSWORD=dbpass
Project 2:
DB_PROJECT2_HOST=0.0.0.0
DB_PROJECT2_DATABASE=dbname
DB_PROJECT2_USERNAME=dbuser
DB_PROJECT2_PASSWORD=dbpass
app\config\database.php
Project 1:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_PROJECT1_HOST'),
'database' => env('DB_PROJECT1_DATABASE'),
'username' => env('DB_PROJECT1_USERNAME'),
'password' => env('DB_PROJECT1_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Project 2:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_PROJECT2_HOST'),
'database' => env('DB_PROJECT2_DATABASE'),
'username' => env('DB_PROJECT2_USERNAME'),
'password' => env('DB_PROJECT2_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Hopefully this is the same issue happening to you so you can quickly test this and see if it applies to you.
#2 Alternative (hardcode method suggested by Tezla):
You may also edit the database configuration file (app\config\database.php) and hardcode the database information directly to avoid configuration leaks:
'mysql' => [
'driver' => 'mysql',
'host' => '0.0.0.0',
'database' => 'dbname',
'username' => 'dbuser',
'password' => 'dbpass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
]

Resolving database connectivity issues on Forge

When I try to login to the app I have setup on Forge, my Laravel app spits out this error:
SQLSTATE[HY000] [1045] Access denied for user 'appname'#'localhost' (using password: YES)
I have the environment variables configured correctly and they work fine on my copy of the site on my local Homestead vagrant box.
Here is the .env.php file that Forge wrote:
return [
'APP_ENV' => 'production',
'DB_DRIVER' => 'mysql',
'DB_HOST' => 'localhost',
'DB_NAME' => 'appname',
'DB_USER' => 'appname',
'DB_PASS' => 'LoNgPaSsWoRd',
];
Here is the relevant contents of app/config/database.php which works locally:
'default' => getenv('DB_DRIVER'),
'connections' => array(
'mysql' => array(
'driver' => getenv('DB_DRIVER'),
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASS'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
I tried dumping the environment values before the first database connection is accessed using dd(getenv('DB_PASS'), getenv('DB_USER')) and they show up correct.
I also tried connecting through MySQL Workbench and resetting the password to exactly what is shown in the environment variable Forge wrote.
None of my other subdomains are having this issue.
What could be going on here and how could I debug this?

Laravel Migration - Says unknown database, but it is created

when I use php artisan migrate, i get the error SQLSTATE[42000] [1049] Unknown database 'databaseName'.
But the database DOES exists! I even tried going back into terminal, logged into mysql and created the database again, and it said that database already exists!
Why is this giving me this error?
I have the same problem. When I run: php artisan migrate.
In my case I use Vagrant with scotch box.
To solve this, enter:
vagrant ssh
cd /var/www/yourproject
php artisan migrate
And all work well.
In your app/config/database.php file change the default value from databaseName to a real database name that you are trying to use in your application, something like this (for mysql driver):
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'your database name', //<-- put the database name
'username' => 'your user name',
'password' => 'your password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
One thing could be your casing. If you read the docs on case sensitivity it says:
the case sensitivity of the underlying operating system plays a part
in the case sensitivity of database and table names. This means
database and table names are not case sensitive in Windows, and case
sensitive in most varieties of Unix. One notable exception is Mac OS
X, which is Unix-based but uses a default file system type (HFS+) that
is not case sensitive.
Then go and check your application database setting found # app/config/database.php.
Something that looks like this:
'mysql' => array(
'read' => array(
'host' => '192.168.1.1',
),
'write' => array(
'host' => '196.168.1.2'
),
'driver' => 'mysql',
'database' => 'databaseName',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
And double check everything.
Also try using snake_case rather than camelCase for you database name.
In my case I had MySQL installed on this port: 3308, and in Laravel env file there was 3306.

DB connection Yii Framework [duplicate]

This question already has answers here:
Database connection error in Yii
(2 answers)
Closed 9 years ago.
I've got a new domain & hosting but I can't connect to the new db.
What I tried:
'db'=>array(
'connectionString' => 'mysql:host=ascodcurro.com.mysql;dbname=ascodcurro_com',
'emulatePrepare' => true,
'username' => 'ascodcurro_com',
'password' => 'xxxx',
'charset' => 'utf8',
),
If I try localhost as always it works fine.
User info from host:
MySQL
server: ascodcurro.com.mysql
DB: ascodcurro_com
user: ascodcurro_com
pw: *****
PhpMyAdmin
PhpMyAdmin: https://dbadmin.one.com/
user: ascodcurro_com
pw: ******
During the initial startup and working with Yii, the first problem that I faced was connecting to the database.
I was getting a really weird error and I was not able to connect to my DB on my Mac OSX Mountain Lion on my XAMPP stack. After countless searches, I finally figured out a method that worked. This is the only way I am able to connect to my DB for Yii.
First check if you can connect to the database normally using the
default configuration by uncommenting the 'db' configuration in the
main.php file. Example :
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=ascodcurro_com',
'emulatePrepare' => true,
'username' => 'username',
'password' => 'pass',
'charset' => 'utf8',
'tablePrefix'=>'',
'enableProfiling'=>true,
'enableParamLogging'=>true,
),
However, if you are still not able to connect to the database even after this, as I wasn't able to connect to mine, try taking this approach :
Make a new php file and type :
<?php phpinfo() ?>
check that page out, find out where 'mysql' is located and find out the 'MYSQL_SOCKET' in it and note the location.
After noting the location down, try this as your 'db' connection string(for example, for me the location is "/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock") :
'connectionString' => 'mysql:unix_socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock;dbname=practice',
And the rest as the basic parameters that you use.
And then try connecting again.
Hopefully, that should connect you to your DB.
Regards,
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=basename',
'emulatePrepare' => true,
'username' => 'username',
'password' => 'pass',
'charset' => 'utf8',
'tablePrefix'=>'',
'enableProfiling'=>true,
'enableParamLogging'=>true,
),
its my config. You get any errors?

CakePHP 2.1 doesn't work on localhost

I deployed my app on a remote host and everything works as expected. But when I try to test my code on localhost, it gives me the following error, without any change to the code working on the host:
Fatal error: Class 'AppHelper' not found in [path]
I am using CakePHP 2.1 and MySQL as my default datasource.
I connect to my local database just like to the remote one (with authentication changes):
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'database',
'prefix' => '',
'encoding' => 'utf8',
);
Why isn't this working on my localhost? Thank you
Two possible things:
either you didnt know about the AppHelper requirement for 2.1:
http://book.cakephp.org/2.0/en/appendices/2-1-migration-guide.html
or you forget to declare the helper at the very top of your class:
App::uses('AppHelper', 'View/Helper');
Although the second one is highly unlikely if you are not running any unit tests.
So my bet is on the first one.