我正在尝试连接到Google Cloud sql上的实例中的数据库,但它告诉我访问被拒绝。
我只是想知道我在这里错过了什么......
这是我的app.yaml文件......
application: guestbookadrian12
version: 1
runtime: php
api_version: 1
handlers:
- url: .*
script: main.php
env_variables:
DEVELOPMENT_DB_HOST: ''
DEVELOPMENT_DB_USERNAME: 'root'
DEVELOPMENT_DB_PASSWORD: 'password'
DEVELOPMENT_DB_NAME: 'guestbookadrian12'
PRODUCTION_CLOUD_SQL_INSTANCE: '/cloudsql/guestbookadrian12:my-cloudsql-instance'
PRODUCTION_DB_USERNAME: 'adrian'
PRODUCTION_DB_PASSWORD: 'password'
PRODUCTION_DB_NAME: 'guestbookadrian12'
这是一些创建连接的PHP代码......
if (strpos(getenv('SERVER_SOFTWARE'), 'Development') === false) {
$conn = mysqli_connect(null,
getenv('PRODUCTION_DB_USERNAME'),
getenv('PRODUCTION_DB_PASSWORD'),
null,
null,
getenv('PRODUCTION_CLOUD_SQL_INSTANCE'));
$db = getenv('PRODUCTION_DB_NAME');
//echo 'Database = : '.$db;
} else {
$conn = mysqli_connect(getenv('DEVELOPMENT_DB_HOST'),
getenv('DEVELOPMENT_DB_USERNAME'),
getenv('DEVELOPMENT_DB_PASSWORD'));
$db = getenv('DEVELOPMENT_DB_NAME');
}
if ($conn->connect_error) {
die("Could not connect to database: $conn->connect_error " .
"[$conn->connect_errno]");
}
if ($conn->query("CREATE DATABASE IF NOT EXISTS $db") === FALSE) {
die("Could not create database: $conn->error [$conn->errno]");
}
我得到的错误是
Could not create database: Access denied for user 'adrian'@'localhost' to database 'guestbookadrian12' [1044]
谢谢