问题描述
对于我的数据库(MySQL),我有两个用户帐户,一个(mydbuser
)用于常规应用程序访问,对所有表具有选择/插入/更新/删除权限,另一个(mydbadmin
)具有管理权限桌子等
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'@'%';
我的Laravel应用配置为使用mydbuser
用户,而mydbadmin
当前用于手动设置表格等.
My Laravel app is configured to use the mydbuser
user, while mydbadmin
is currently used for manually setting up the tables, etc.
现在,我想开始使用Artisan migrations
和seeding
来为应用程序的新实例创建数据库,但是在标准应用程序配置下,migrate
仅具有访问权限较小的帐户的权限,因此实际上根本无法创建/删除表.
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.
运行时是否有一种方法可以覆盖在database.php中配置的数据库用户/密码
Is there a way of overriding the database user/password configured in database.php when I run
php artisan migrate:install
和其他迁移命令?也许某些命令行开关可以让我指定mydbadmin
用户和密码?甚至只是指向其他数据库配置设置?
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?
推荐答案
您可以使用:
php artisan migrate:install --database=seconddb
,但是您需要在database.php
配置文件中定义此seconddb
连接.当然,运行此命令只会创建migrations
表,仅此而已,因此,如果要进行标准迁移,则需要使用:
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
并进行播种:
php artisan db:seed --database=seconddb
database.php
文件配置示例:
'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' => '',
),
如果需要有关参数的其他信息,则可以始终运行--help
参数,例如:
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数据库配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!