简体   繁体   中英

how to connect to azure database for mysql, from azure app service with wordpress docker image?

I have an azure app service, using the latest wordpress image from docker hub . The screenshot for the azure app service: 在此处输入图像描述

Then in the azure app service -> application setting, I added the following key/value pairs which will be used to connect Azure database for mysql:

  1. WORDPRESS_DB_HOST
  2. WORDPRESS_DB_NAME
  3. WORDPRESS_DB_PASSSWORD
  4. WORDPRESS_DB_USER

screenshot: 在此处输入图像描述

Inside my Azure database for mysql, I have enabled public access / allow public access from any azure service / also add my client ip and this ip range 0.0.0.0 - 255.255.255.255. I can access it from my client and create the database which will be used by azure app service. Screenshot like below: 在此处输入图像描述

in server parameters, I also turn off the require_secure_transport setting: 在此处输入图像描述

At last, I tried to launch the site, but it throws the error "Error establishing a database connection", screenshot below: 在此处输入图像描述

I'm new to wordpress / docker, and don't know how to fix this issue. I also reviewed some videos / docs, and didn't see any other configuration differences. Could you please guide me how to fix this issue? Thanks very much.

You received this error message.

Warning: mysqli_real_connect(): (HY000/1045)>: Access denied for user 'ivan'@'52.xx.xxx.xx' (using password: YES)

It means MySQL received, processed, and rejected your WordPress instance's attempt to connect. So you know the hostname is right and your cloud provider's firewall settings allow your WordPress instance to exchange network data with your MySQL instance.

What's wrong?

MySQL's user name / account name setup has a quirk. An account name can look like 'ivan'@'localhost' or 'ivan'@'%' (or even something like 'ivan'@'192.0.22.33' ).

The first of those only allows login from localhost (or via tunneling via ssh). The second allows login from '%' , meaning any host. You need the second one for your WordPress instance to get access to MySQL.

When you're logged in to MySQL from your machine, do this.

SELECT host, user FROM mysql.user WHERE user='ivan';

You should see two rows, like these

 host       user  
 ----       ---   
 %          ivan  
 localhost  ivan 

It's possible the account with '%' as the host is missing. If so that means you need to create another MySQL account and give it access to your database . Do that like this.

CREATE USER 'ivan'@'%' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;

Next, make sure the user account you just created -- the one your WordPress software will use to connect to MySQL -- has access to your database.

GRANT ALL PRIVILEGES ON wordpress.* TO 'ivan'@'%';
FLUSH PRIVILEGES;

If you still get the error message, it's possible the password on your 'ivan'@'%' account doesn't match what you put into your WordPress configuration. You can change it with

ALTER USER 'ivan'@'%' IDENTIFIED BY 'your_password'; 
FLUSH PRIVILEGES;

If it still gives the same error message, it's possible that your cloud vendor requires TLS to connect to MySQL. You may want to consult their support team about that.

(This is a common stumbling block setting up new WordPress instances.)

ok just to keep and make things clear. all IPs can connect to the DB but are you actually authorized to read/write date in the DB?

IE this might be a permission/privilege issue. I suggest double checking user privileges and determine who can do what on your DB

Best Regards. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM