Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error occurs while running sql command in queue. #18386

Closed
YangEndly opened this issue Mar 17, 2017 · 8 comments
Closed

Error occurs while running sql command in queue. #18386

YangEndly opened this issue Mar 17, 2017 · 8 comments

Comments

@YangEndly
Copy link

YangEndly commented Mar 17, 2017

  • Laravel Version:5.3
  • PHP Version:7.1
  • Database Driver & Version: mysql5.7.9
    -local development:wamp

My online production environment: php and mysql are two independent servers. It does not work.
The local development environment: php and mysql are the same server. It can work well.

Description:

While running sql command, mysql that is connected to PDO is 127.0.0.1. However, my mysql is another server so that it does not work. The error is as follows:
Stack trace:
#0 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(119): PDO->__construct('mysql:host=127....', '', '', Array)
#1 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(56): Illuminate\Database\Connectors\Connector->createPdoConnection('mysql:host=127....', '', '', Array)
#2 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php(24): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=127....', Array, Array)
#3 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php(126): Illuminate\Database\Connectors\MySqlConnector->connect(Array)
#4 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors{closure}()
#5 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php(965): call_user_func(Object(Closure))
#6 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php(476): Illuminate\Database\Connection->getPdo()
#7 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php(763): Illuminate\Database\Connection->Illuminate\Database{closure}(Object(Illuminate\Database\MySqlConnection), 'insert into in...', Array) #8 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php(726): Illuminate\Database\Connection->runQueryCallback('insert into in...', Array, Object(Closure))
#9 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php(481): Illuminate\Database\Connection->run('insert into in...', Array, Object(Closure)) #10 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php(435): Illuminate\Database\Connection->statement('insert into in...', Array)
#11 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php(32): Illuminate\Database\Connection->insert('insert into in...', Array) #12 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2154): Illuminate\Database\Query\Processors\Processor->processInsertGetId(Object(Illuminate\Database\Query\Builder), 'insert into in...', Array, 'id')
#13 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1470): Illuminate\Database\Query\Builder->insertGetId(Array, 'id')
#14 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1609): Illuminate\Database\Eloquent\Builder->__call('insertGetId', Array)
#15 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1574): Illuminate\Database\Eloquent\Model->insertAndSetId(Object(Illuminate\Database\Eloquent\Builder), Array)
#16 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1471): Illuminate\Database\Eloquent\Model->performInsert(Object(Illuminate\Database\Eloquent\Builder))
#17 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(561): Illuminate\Database\Eloquent\Model->save()
#18 /data/www/yungou.ay/app/Jobs/SendNotifyPurchase.php(46): Illuminate\Database\Eloquent\Model::create(Array)
#19 [internal function]: App\Jobs\SendNotifyPurchase->handle(Object(App\Http\Controllers\JPushController))
#20 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#21 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#22 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Bus\Dispatcher->Illuminate\Bus{closure}(Object(App\Jobs\SendNotifyPurchase))
#23 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(App\Jobs\SendNotifyPurchase))
#24 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#25 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(47): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendNotifyPurchase), false)
#26 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(73): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#27 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(203): Illuminate\Queue\Jobs\Job->fire()
#28 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(152): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Illuminate\Queue\WorkerOptions))
#29 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(100): Illuminate\Queue\Worker->runNextJob('redis', 'default', Object(Illuminate\Queue\WorkerOptions))
#30 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(83): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default')
#31 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#32 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#33 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#34 /data/www/yungou.ay/vendor/symfony/console/Command/Command.php(261): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /data/www/yungou.ay/vendor/symfony/console/Application.php(817): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /data/www/yungou.ay/vendor/symfony/console/Application.php(185): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /data/www/yungou.ay/vendor/symfony/console/Application.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 /data/www/yungou.ay/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#41 {main}

Next Illuminate\Database\QueryException: SQLSTATE[HY000] [1045] Access denied for user 'treasure'@'127.0.0.1' (using password: YES) (SQL: insert into information (info_cate_id, title, desc, consumer_id, type, count, updated_at, created_at) values (3, Announcing soon!, Check who is lucky! Click to view: SAMSUNG MB-MP16DA/EU 16Gb Evo Micro SD Card, 10073, 2, 1, 2017-03-17 06:07:31, 2017-03-17 06:07:31)) in /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php:770
Stack trace:
#0 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php(726): Illuminate\Database\Connection->runQueryCallback('insert into in...', Array, Object(Closure)) #1 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php(481): Illuminate\Database\Connection->run('insert into in...', Array, Object(Closure))
#2 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Connection.php(435): Illuminate\Database\Connection->statement('insert into in...', Array) #3 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php(32): Illuminate\Database\Connection->insert('insert into in...', Array)
#4 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2154): Illuminate\Database\Query\Processors\Processor->processInsertGetId(Object(Illuminate\Database\Query\Builder), 'insert into `in...', Array, 'id')
#5 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1470): Illuminate\Database\Query\Builder->insertGetId(Array, 'id')
#6 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1609): Illuminate\Database\Eloquent\Builder->__call('insertGetId', Array)
#7 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1574): Illuminate\Database\Eloquent\Model->insertAndSetId(Object(Illuminate\Database\Eloquent\Builder), Array)
#8 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1471): Illuminate\Database\Eloquent\Model->performInsert(Object(Illuminate\Database\Eloquent\Builder))
#9 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(561): Illuminate\Database\Eloquent\Model->save()
#10 /data/www/yungou.ay/app/Jobs/SendNotifyPurchase.php(46): Illuminate\Database\Eloquent\Model::create(Array)
#11 [internal function]: App\Jobs\SendNotifyPurchase->handle(Object(App\Http\Controllers\JPushController))
#12 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#13 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#14 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Bus\Dispatcher->Illuminate\Bus{closure}(Object(App\Jobs\SendNotifyPurchase))
#15 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(App\Jobs\SendNotifyPurchase))
#16 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#17 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(47): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\SendNotifyPurchase), false)
#18 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(73): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#19 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(203): Illuminate\Queue\Jobs\Job->fire()
#20 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(152): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Illuminate\Queue\WorkerOptions))
#21 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(100): Illuminate\Queue\Worker->runNextJob('redis', 'default', Object(Illuminate\Queue\WorkerOptions))
#22 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(83): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default')
#23 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#24 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#25 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#26 /data/www/yungou.ay/vendor/symfony/console/Command/Command.php(261): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 /data/www/yungou.ay/vendor/symfony/console/Application.php(817): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 /data/www/yungou.ay/vendor/symfony/console/Application.php(185): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 /data/www/yungou.ay/vendor/symfony/console/Application.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#31 /data/www/yungou.ay/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 /data/www/yungou.ay/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 {main}

Steps To Reproduce:

@mrliptontea
Copy link

@YangEndly that's an error with your configuration, you said it yourself, MySQL is on a separate server.

Update DB_HOST to your MySQL's external IP address.

@YangEndly
Copy link
Author

@mrliptontea Thank you for your attention. I am certain that normal outside mysql address is set in my DB_HOST but error still occurs. My doubt: is it a bug that default connection of sql command in queue is 127.0.0.1?

@edenreich
Copy link
Contributor

@YangEndly if I understood right you are trying to set DB_HOST other than 127.0.0.1 but it sets you this as default ?

did you cleared your cache in the bootstrap folder ?

the configuration are probably cached..try:
php artisan clear-compiled
composer dump-autoload

@bradleyy1012
Copy link

if you do php artisan clear-compiled dont forget php artisan config:clear after :P

@YangEndly
Copy link
Author

@edenreich I already tried to clear cache in bootstrap folder, and also tried
php artisan clear-compiled
composer dump-autoload
but still the same, do you have any other suggestions?

Thanks again...

@YangEndly
Copy link
Author

this is class
class SendNotifyPurchase implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;

private $product;
private $alias;

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($alias,$product)
{
    $this->product=$product;
    $this->alias=$alias;
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle(JPushController $JPushController)
{
    $alert = "Check who is lucky! Click to view: $this->product";
    $title = 'Announcing soon!';
     Information::create([
        'info_cate_id'=>3,
        'title'=>$title,
        'desc'=>$alert,
        'consumer_id'=>implode(' ',$this->alias),
        'type'=>2,
        'count'=>1,
    ]);
    $JPushController->send_notify_one($alert,$this->alias,$title,'0');
}

}

@mrliptontea
Copy link

The error message says Access denied for user 'treasure'@'127.0.0.1' - Is your db user treasure?
If yes, can you confirm that in the file where you set DB_USERNAME=treasure you also set DB_HOST to something else than 127.0.0.1?

Relevant command is php artisan config:clear.

Also, if run your job in the queue, run php artisan queue:restart so workers can pick up the updated config file.

@YangEndly
Copy link
Author

@mrliptontea
Thank you so much for helping me solving the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants