Overriding Default Laravel database configuration for artisan migrate commands(覆盖工匠迁移命令的默认 Laravel 数据库配置)
问题描述
For my database (MySQL), I have two user accounts, one (mydbuser
) for general application access with select/inset/update/delete permissions on all tables, the other (mydbadmin
) with privilege to manage tables, etc
CREATE USER 'mydbadmin'@'%' IDENTIFIED BY 'ultrasecret password';
GRANT ALL ON mydb.* TO 'mydbadmin'@'%';
CREATE USER 'mydbuser'@'%' IDENTIFIED BY 'not quite so secure password';
GRANT SELECT, INSERT, UPDATE, DELETE ON mydb.* TO 'mydbuser'@'%';
My Laravel app is configured to use the mydbuser
user, while mydbadmin
is currently used for manually setting up the tables, etc.
Now, I want to start using Artisan migrations
and seeding
to handle creating the database for new instances of the application, but with the standard application configuration, migrate
only has access to the lesser-privileged account, so can't actually create/drop the tables at all.
Is there a way of overriding the database user/password configured in database.php when I run
php artisan migrate:install
and other migrate commands? Some command line switch perhaps, that would allow me to specify the mydbadmin
user and password? Or even just to point to a different database configuration setting?
You may use:
php artisan migrate:install --database=seconddb
but you need to have defined this seconddb
connection in your database.php
config file. Of course running this command you will only create migrations
table, nothing more, so if you want to make standard migration you need to use:
php artisan migrate --database=seconddb
and for seeding:
php artisan db:seed --database=seconddb
Example database.php
file configuration:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'maindb',
'username' => 'root',
'password' => 'pass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'seconddb' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'otherdb',
'username' => 'user',
'password' => 'otherpass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
And in case you need other information about paramters, you can always run --help
argument for example:
php artisan migrate:install --help
php artisan migrate --help
这篇关于覆盖工匠迁移命令的默认 Laravel 数据库配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:覆盖工匠迁移命令的默认 Laravel 数据库配置
基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01