[SAE] SAE MySQL Cross-Application Authorization

As SAE (Sina App Engine) pricing continues to rise, cost savings become increasingly important. Starting March 2016, shared MySQL also began incurring charges, making it important for multiple applications to share a single MySQL instance.

Steps to Share a Single MySQL Across Multiple Applications

  1. Assume you have multiple applications (APP1, APP2, APP3): Only APP1 retains the shared MySQL, while APP2 and APP3 will use APP1’s MySQL.
  2. Export APP2 and APP3’s MySQL databases as backups, then delete APP2 and APP3’s MySQL instances. This way, APP2 and APP3’s MySQL will be uninitialized and no longer incur charges.
  3. Import APP2 and APP3’s database files (*.sql) into APP1’s MySQL. Before importing, make sure table names don’t conflict.
  4. In APP1’s MySQL settings, click Cross-Application Authorization to select applications under your account or other accounts. Authorize APP2 and APP3 here.
  5. Write a script to display APP1’s MySQL connection information for the authorized applications APP2 and APP3 to use (this will expose database credentials, so proceed with caution and delete the script promptly).

Related code:

1
2
3
4
5
6
7
8
9
<?php
header("Content-type:text/html;charset=utf-8");
echo "Username   :".SAE_MYSQL_USER."<br>";
echo "Password   :".SAE_MYSQL_PASS."<br>";
echo "Master Host:".SAE_MYSQL_HOST_M."<br>";
echo "Slave Host :".SAE_MYSQL_HOST_S."<br>";
echo "Port       :".SAE_MYSQL_PORT."<br>";
echo "Database   :".SAE_MYSQL_DB."<br>";
?>
  1. Run the script: The page will display APP1’s MySQL information. Use this information in your other applications (such as APP2 and APP3) to connect to the database.

Notes

  • Security: Since the script exposes sensitive information such as database username and password, make sure to delete the script promptly after use to prevent information leakage.
  • Table name conflicts: When importing APP2 and APP3’s database files into APP1’s MySQL, ensure there are no table name conflicts. If conflicts exist, consider renaming tables before importing.
  • Authorization management: When performing cross-application authorization on the SAE management platform, only authorize necessary applications to avoid unnecessary permission exposure.

Through these steps, you can effectively reduce SAE MySQL costs while ensuring multiple applications can access the shared database normally.

Licensed under CC BY-NC-SA 4.0