Laravel 5.4 - Custom Artisan Command "Access is denied." -
so made custom artisan command dump sql file database.
here's inside command.
i named db:dump syntax:
protected $signature = 'db:dump'; next command itself:
public function handle() { $ds = directory_separator; $host = env('db_host'); $username = env('db_username'); $password = env('db_password'); $database = env('db_database'); $ts = time(); $path = database_path() . $ds . 'backups' . $ds . date('y', $ts) . $ds . date('m', $ts) . $ds . date('d', $ts) . $ds; $file = date('y-m-d-his', $ts) . '-dump-' . $database . '.sql'; $command = sprintf('mysqldump -h %s -u %s -p\'%s\' %s > %s', $host, $username, $password, $database, $path . $file); if (!is_dir($path)) { mkdir($path, 0755, true); } exec($command); } so of info needed inside .env file. if help, i'll provide what's inside it:
app_name=laravel app_env=local app_key=base64:3wuxkys70vx+v/ic5qjuvcmfbzsqtkjehiqa7q9s9gk= app_debug=true app_log_level=debug app_url=http://localhost db_connection=mysql db_host=127.0.0.1 db_port=3306 db_database=db_salesandinventory db_username=root db_password= broadcast_driver=log cache_driver=file session_driver=file queue_driver=sync redis_host=127.0.0.1 redis_password=null redis_port=6379 mail_driver=smtp mail_host=smtp.mailtrap.io mail_port=2525 mail_username=null mail_password=null mail_encryption=null pusher_app_id= pusher_app_key= pusher_app_secret= with info, everything's ready , have worked.
but whenever execute command in command prompt:
php artisan db:dump
it says "access denied."
i lost lead here, don't know problem.
edit: when replace command $this->info('test'); work. it's console.log command or sort. wanted there's wrong in command restricts me doing it.
from comments, describe command script generating , trying execute (as seen when dd($command) instead of trying exec($command)):
mysqldump -h 127.0.0.1 -u root -p'' db_salesandinventory > <output-file> where <output-file> in home directory presumably writable. mentioned running command manually fails same permissions error. problem has nothing laravel, access mysql server.
first of test if username , password correct. try, on console:
mysql -u root -p db_salesandinventory (without -h). prompted password, enter 1 using in script. if not work, using wrong u/p, fix , try script again.
if does work, means root user not allowed connect 127.0.0.1. mysql, localhost not same 127.0.0.1, , you'll need enable access root user using ip, as described in question.
Comments
Post a Comment