I am running the following sets of commands to automatically install a certain drupal website
phpMyAdmin, has a database named x_init_testing, and has a user testing with password secret that can log into it (a manual drupal install is working fine, and there is an access to the db with the user and the password)
First, I am running
mysqladmin -utesting -psecret drop x_init_testing -f
mysqladmin -utesting -psecret create x_init_testing
both of these work fine, and clear the database (which should allow drush to install a new site on it)
then I am running
drush si profileName --db-url=mysql://root#127.0.0.1/x_init_testing -y --account-pass=secret
root has a password (i.e., it is not empty)
and drush sql connect does work
drush sql-connect
mysql --user=testing --password=secret --database=x_init_testing --host=127.0.0.1 --port=8889
the site is stored on MAMP (i.e., locally on my machine so no network problems)
and my settings.php file is configured with the db
*/
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'x_init_testing',
'username' => 'testing',
'password' => 'secret',
'host' => '127.0.0.1',
'port' => '8889',
'driver' => 'mysql',
'prefix' => '',
),
),
);
Still running the drush si results in
You are about to CREATE the 'x_init_testing' database. Do you want to continue? (y/n): y
Failed to create database: ERROR 1045 (28000): Access denied for user[error]
'root'#'localhost' (using password: NO)
If needed I am using: Drush Version 8.1.6, and it seems that I am using all the required arguments for the si
I think I found the issue, in theory the root user starts with no password, and this is why the command worked on machines that did not set a root password
changing the si command to :
drush si profileName --db-url=mysql://root:password#127.0.0.1/x_init_testing -y --account-pass=secret
I have old project which built using Laravel 4.2.I am getting following error
PDOException (1045)
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
I have googled and tried every think but i couldn't able to fix it
.env file
APP_KEY=az9tq5VHQCV9g5m2CsgY89jtijrCMgEA
DB_HOST=localhost
DB_DATABASE=billing
DB_USERNAME=root
DB_PASSWORD=1234
database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'billing',
'username' => 'root',
'password' => '1234',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Can any one guide me where m doing wrong ?
Note: Before asking question i tried by updating composer update as well as most of the stackoverflow answers.
Updated
I have tested this connection by creating php file
<?php
$servername = "localhost";
$username = "root";
$password = "1234";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
i will get Connected successfully message
My error was Laravel Access denied for user 'root'#'localhost' (using password: NO)
and I only got this error at my host site.
In .env I changed:
DB_USERNAME=user
DB_PASSWORD=password
to:
DB_USERNAME='user'
DB_PASSWORD='password'
Worked for me!
DB_HOST="localhost" worked for me.
And to be safe, wrap .env variables in double quotes to avoid ENV errors:
DB_USERNAME="root"
DB_PASSWORD="#Password"
These will give errors: DB_PASSWORD=#Password, DB_PASSWORD=I have spaces
# is a start of a comment and is exactly the same as //
Run php artisan serve after configure .env, not before.
Laravel 4.x doesn't even support ENV files. You just have to see whether settings in ./config/[env name]/database.php are correct.
I just ran into the same problem on a new Laravel install.
The problem was that I was connecting to my ubuntu localhost mysql server instead of to the vagrant box's mysql server that was on it's own ip address '192.168.10.10'.
I changed over to that and all worked a charm :)
I'm test in Laravel 5.6.33 and i see this error: "Access denied for user 'root'#'localhost'", but the username and password is correct.
In this version i think of this is a BUG, i change DB_HOST, from 127.0.0.1 to localhost and works!
DB_HOST=127.0.0.1 (before)
DB_HOST=localhost (after)
Try In .ENV
APP_ENV=local
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=billing
DB_USERNAME=root
DB_PASSWORD=1234
And Delete Cache Files From Root/boostrap/chache/files
and Run The App
The error says it all, Laravel can't connect to a DB. Check priveleges and make sure the DB exists. Also, try to connect to a DB with a client, like MySQL Workbench using same login and password. This will give a hint about what you can do to fix this. If you can't do this, it's not a Laravel issue.
Try This
.env file
APP_ENV=local
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=billing
DB_USERNAME=root
DB_PASSWORD=1234
config/database.php
default' => env('DB_CONNECTION', 'mysql'),
'mysql' => array(
'driver' => 'mysql',
'host' => env('DB_HOST','localhost'),
'database' => env('DB_DATABASE','billing'),
'username' => env('DB_USERNAME','root'),
'password' => env('DB_PASSWORD', '1234'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
Else checkout the .env file and check the connection
I got the same problem. You should add "" to the DB_USERNAME and DB_PASSWORD
So,
Step 1: DB_USERNAME="root" DB_PASSWORD="1234"
Step 2: Run "php artisan config:clear"
Step 3: Run "php artisan cache:clear"
please delete config file located at bootstrap/cache/config.php
it will be autogenerated when you run php artisan config:cache command
it will work
I faced the same problem when learning laravel using homestead, the problem happened when I try to open a page. It tried to connect to database but got rejected, although I can connect to the database using mysql command line.
The problem was I had wrong assumption that since homestead forward web server request from guest to host, the same thing is also same with myqsl, but apparently it is not.
Homestead has it's own mysql service, so my problem was fixed by:
- homestead ssh into the guest machine
- mysql -u root -p to connect to mysql command line, default password is "secret"
- create the database, but you need to change your password first, just change into the same password as in mysql root's password in your host machine for convenience
- exit the mysql cli and
- php artisan migrate to create the tables
- refresh your browser, now it should be able to connect to your db
Access denied for user 'root'#'localhost' (using password: YES)
The error was coming? The possible reason is your database
connection.If the database is not connect then throw the error.
So Check the database releted all things and If all things is correct.
If not solved then change
DB_HOST=127.0.0.1 TO DB_HOST=localhost
Make sure your .env is using the correct port number. If you're using phpMyAdmin this is how is setup:
MariaDB defaults to 3306
and
MySQL defaults to 3308
So change your .env to use port 3308 for MySQL. I hope this helps!
I changed this line DB_HOST=127.0.0.1 in .env to DB_HOST=localhost and it worked for me.
I had a similar problem, the password is the major issue in such communication, see my picture below, i solved it after changing password, php artisan serve and then reloading my view. It worked.
please login to mysql or phpmyadmin and change your password.
enter image description here
It sounds kind of obvious, but check the credentials of the database.
For me something was wrong in the env file. So I created a fresh installation, copied the env file from there and updated the credentials and it worked.
If you're using docker and still having issues with user access denied issues, you may want to try starting over fresh with the DB, which is was what it took for me.
First, I figured out where my DB data volumes were being stored in my docker-compose.yml file, which ended up being here: [app root dir]/docker/db/data/
db:
container_name: ${APP_NAME}_db
image: mysql:8.0
ports:
- 33060:3306
volumes:
- ./docker/db/data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_DATABASE}
Then I ran this in the app root directory to remove all the docker containers.
docker-compose rm -v
Next I navigated to the DB data files and removed all of them:
cd ~/[app root dir]/API/docker/db/data
sudo rm -rf ./*
Finally, I started up the containers and was then able to connect with my database user credentials.
docker-compose up --build --force-recreate --no-deps
REFERENCE: https://github.com/docker-library/mysql/issues/51
If the username and password are correct and the problem still persists, try clearing the cache using the following method
Route::get('/clear-cache', function () {
Artisan::call('cache:clear');
Artisan::call('route:clear');`
});
Laravel 6 just set secret instead of empty space.
DB_PASSWORD=secret
I'm deploying a PHP app which uses Doctrine as ORM in Openshift. In my post_deploy action hook I run doctrine orm schema-tool to update the DB but I'm getting a Connection Timeout error.
As I'm farily new to Openshift, what is the best way to setup the database on Openshift?
UPDATE
I have two gears, one for the app and other for MySQL. I ssh into the app gear and ran
doctrine orm:schema-tool:update
Which results in a Connection Timeout error.
If I try
mysql -h $OPENSHIFT_MYSQL_DB_HOST
-p $OPENSHIFT_MYSQL_DB_PORT
-u $OPENSHIFT_MYSQL_DB_USERNAME
-P $OPENSHIFT_MYSQL_DB_PASSWORD
-
I get a prompt and the subsequent error after entering the MySQL password informed by Openshift.
Enter password:
ERROR 1049 (42000): Unknown database '<obsfucated_password>'
UDPATE 2:
As an unrelated thing pointed by Martin below, the mysql syntax is wrong. After fixing it I found that
mysql -u $OPENSHIFT_MYSQL_DB_USERNAME
-h $OPENSHIFT_MYSQL_DB_HOST
-P $OPENSHIFT_MYSQL_DB_PORT
-D $OPENSHIFT_APP_NAME
-p $OPENSHIFT_MYSQL_DB_PASSWORD
Results in
Enter password:
ERROR 1045 (28000): Access denied for user 'adminjbEnwMq'#'10.63.71.68' (using password: NO)
While runnning
mysql -u $OPENSHIFT_MYSQL_DB_USERNAME
-h $OPENSHIFT_MYSQL_DB_HOST
-P $OPENSHIFT_MYSQL_DB_PORT
-D $OPENSHIFT_APP_NAME
Connects successfully.
UPDATE 3
On the PHP side I'm running the following test code, thanks to this answer:
<?php
require_once "vendor/autoload.php";
require_once "vendor/doctrine/common/lib/Doctrine/Common/ClassLoader.php";
use Doctrine\DBAL\Configuration;
$config = new \Doctrine\DBAL\Configuration();
define('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST'));
define('DB_PORT',getenv('OPENSHIFT_MYSQL_DB_PORT'));
define('DB_USER',getenv('OPENSHIFT_MYSQL_DB_USERNAME'));
define('DB_PASS',getenv('OPENSHIFT_MYSQL_DB_PASSWORD'));
define('DB_NAME',getenv('OPENSHIFT_GEAR_NAME'));
$connectionParams = array(
'dbname' => DB_NAME,
'user' => DB_USER,
'password' => DB_PASS,
'host' => DB_HOST,
'driver' => 'pdo_mysql',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
var_dump($conn);
echo $conn->query("SHOW TABLES");
?>
And I get the same timeout error.
I cannot help you with your doctrine question, but the mysql command syntax is actually wrong.
Usage: mysql [OPTIONS] [database]
As you can see in your output, mysql is interpreting your password as the database name.
If you want to specify the optionas as you showed above you need to add an '=' between the option and the option-value.
mysql --host=$OPENSHIFT_MYSQL_DB_HOST
--port=$OPENSHIFT_MYSQL_DB_PORT
--user=$OPENSHIFT_MYSQL_DB_USERNAME
--password=$OPENSHIFT_MYSQL_DB_PASSWORD
If you want to add the database name to your command, the default database name is $OPENSHIFT_APP_NAME. Just add it at the end of your mysql command.
To see all the mysql options do mysql --help
Maybe it was because I was always working on this after 23hs, but this morning I realized I was not setting the port connection parameter. The following code works like a charm:
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => getenv('OPENSHIFT_MYSQL_DB_HOST')?: '127.0.0.1',
'port' => getenv('OPENSHIFT_MYSQL_DB_PORT')?:'3306',
'user' => getenv('OPENSHIFT_MYSQL_DB_USERNAME')?: 'stpe',
'password' => getenv('OPENSHIFT_MYSQL_DB_PASSWORD')?: 'thefallen1',
'dbname' => getenv('OPENSHIFT_APP_NAME')?:'stpe',
);
So here's my array containing my credentials.
'mysql' => array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '*',
'db' => 's'
)
And the actual connection
try{
$this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'),Config::get('mysql/username'),Config::get('mysql/username'));
}
catch(PDOException $e){
die($e->getMessage());
}
And this is the error I get
SQLSTATE[28000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
But I am aware that this means access is denied, but the credentials are 100% correct. I also tested via command line and through workbench.
Are you sure a password is set? What happens if you attempt to connect via the command line line this:
/Applications/MAMP/Library/bin/mysql -uroot
Also, the password for root in MAMP is root. This is no deep/dark secret. Is the * in your example valid?
And in your connector, have you tried using localhost instead of 127.0.0.1? I have seen some MySQL setups work with one but not the other when it should be both.
EDIT: If you somehow mucked up the root password, don’t panic! You can still reset it this way. Warning, some folks feel this method of password reset is “risky” but that is generally true for a production server or any server in the wild. From MAMP on your desktop, this should be 100% safe.
First, stop MAMP entirely.
Next, start it up again from the command line with the skip-grant-tables option like so:
/Applications/MAMP/Library/bin/mysqld --skip-grant-tables
Once that is done, you can login with 100% no password just like this:
/Applications/MAMP/Library/bin/mysql -uroot
Then you can reset the root password with this one-liner:
UPDATE user SET Password=PASSWORD('root') WHERE user='root'; FLUSH PRIVILEGES; exit;
Okay, now find the process running the MySQL daemon with skip-grant-tables from the command line like this:
ps -u [your system username] | grep "mysqld --skip-grant-tables"
A list with two items should be returned: One is the mysqld & the other is the command you just made. Something like this:
502 1759 ttys004 0:00.11 /Applications/MAMP/Library/bin/mysqld --skip-grant-tables
502 1766 ttys004 0:00.00 grep mysqld
Okay, so now we know the mysqld with skip-grant-tables has process ID 1759, go ahead and kill that like so:
kill 1759
Restart MAMP again & the root password should work as expected now.
Try adding a port to your array! For me, it worked! The port is 8889 by default. You can change it by going to MAMP>Preferences, then the Ports tab. Here's what I think (I haven't tried this!):
'mysql' => array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '*',
'port' => '8889',
'db' => 's'
)
You use Config::get('mysql/username') twice, the second should be Config::get('mysql/password')
EDIT: I finally realised artisan is trying to connect to my machine instead of the remote database host specified in config. I assumed it would retrieve the hosts address along with the username and password. I'll try to specify the host's address on commandline and post back.
EDIT 2: I found the problem. Technical support for the host mislead me to my first edit. The problem was a mismatch in the password between a '1' and an 'l'. Sorry to have wasted your time.
I'm developing a Laravel 4 web app and I'm trying to execute migrations from sentry into a remote mysql database. I have been able to connect via phpmyadmin using the same credentials stored into laravel without any hassle, but artisan won't work.
Here's artisan command and output:
$ php artisan migrate --package=cartalyst/sentry
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'myuser'#'mypc' (using password: YES)
migrate [--bench[="..."]] [--database[="..."]] [--path[="..."]] [--package[="..."]] [-- pretend] [--seed]
Laravel connection config:
'default' => 'mysql',
[...]
'mysql' => array(
'driver' => 'mysql',
'host' => 'hostname.example.com',
'database' => 'mydb',
'username' => 'myuser',
'password' => 'supersecretpassword',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I don't have mysql installed locally, just apache, php and phpmyadmin. My box is archlinux and I don't have access to the remote host.
Any ideas?
You need to grant rights to that user on that host (this is the machine from where you connect):
GRANT ALL ON mydb.* TO myuser#mypc IDENTIFIED by 'supersecretpassword';