先说短版:
我希望该命令doctrine:database:create
使用正确/定义的字符集和排序规则创建数据库。如何做到这一点?(在最好的情况下,无需更改服务器上的任何全局设置。)
详细版本:
上下文是 Symfony 4 应用程序和 Doctrine 2。DBMS:MySQL,操作系统:Ubuntu 14.04。我想用 Doctrine 创建数据库:
$ bin/console doctrine:database:create
后台执行Doctrine的SQL语句为:
CREATE DATABASE `mydb`
意思是:它不使用charset
and中的collate
设置,.../config/packages/doctrine.yaml
并且DATABASE_URL
in.../.env
被忽略。
.../config/packages/doctrine.yaml
parameters:
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'
mapping_types:
enum: string
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Base/Entity'
prefix: 'App\Base\Entity'
alias: App
.../.env
###> doctrine/doctrine-bundle ###
DATABASE_URL=mysql://root:pwd@127.0.0.1:3306/mydb?charset=utf8mb4
###< doctrine/doctrine-bundle ###
数据库DEFAULT_CHARACTER_SET_NAME
是latin1
然后DEFAULT_COLLATION_NAME
是latin1_swedish_ci
:
SELECT
`DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`
FROM
information_schema.SCHEMATA
WHERE
schema_name = 'mydb'
;
+----------------------------+------------------------+
| DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME |
+----------------------------+------------------------+
| latin1 | latin1_swedish_ci |
+----------------------------+------------------------+