Database FAQ
This topic summarizes frequently asked questions (FAQs) about Web Hosting databases. It covers common functional issues, such as which database engines are supported and whether you can enable the event_scheduler component, as well as operational issues, such as how to expand database space and resolve import failures. This topic helps you efficiently troubleshoot and resolve these issues.
-
Functional issues
-
Operational issues
Which databases does Web Hosting support?
Web Hosting supports different databases based on the operating system:
-
Linux-based Web Hosting supports MySQL and SQLite databases.
-
Windows-based Web Hosting supports SQL Server and Access databases.
For more information, see Supported database versions for Web Hosting.
Can I enable event_scheduler for MySQL databases?
The event_scheduler parameter is disabled by default for MySQL databases on Web Hosting, and you cannot manually enable this parameter.
The event_scheduler is a timer-like component in MySQL. You can use it to run an SQL statement or a block of statements at a specific time or at regular intervals.
To verify that the event_scheduler parameter is set to OFF, follow these steps:
-
Log on to your MySQL database.
For more information, see Log on to a database by using the web version of DMS.
-
In the top menu bar, select SQL Window.
-
In the SQL Window editor, enter
show variables like '%sche%';and click Execute(F8).After the command runs, the status of
event_schedulerisOFFon the Result Set 1 tab.
Differences between MySQL and MySQLi functions
PHP can interact with MySQL databases by using two types of functions: MySQL and MySQLi. The following sections describe the differences and provide code examples.
-
MySQL functions
-
Before PHP 5.0, PHP's MySQL functions were generally used to operate on MySQL databases, which is a procedure-oriented approach. For example, the function
mysql_query(). -
MySQL functions use non-persistent connections. Each time you connect, a new connection process is created.
-
MySQL function syntax: For a
querystatement, the resource identifier inmysql_query(SQL statement, resource identifier)is an optional parameter that defaults to the last opened connection or resource. -
The following example shows how to use MySQL functions to connect to a database and retrieve the value of a specific field:
$conn = mysql_connect('localhost', 'user', 'password'); // Connect to the MySQL database mysql_select_db('data_base'); // Select the database $result = mysql_query('select * from data_base'); // The second parameter is optional and specifies the connection to use $row = mysql_fetch_row($result); // Fetch a single row of data echo $row[0]; // Output the value of the first field
-
-
MySQLi functions
-
The MySQLi functions were introduced after PHP 5.0. They are an enhanced, object-oriented version of the MySQL functions, and are more stable, efficient, and secure. For example, the function
mysqli_query().NoteMySQLi not only encapsulates common database operations but also provides support for advanced features like transactions.
-
MySQLi functions use a persistent connection. Even if you run the MySQLi connection function multiple times, the same connection process is reused. This reduces server resource consumption.
-
MySQLi function syntax: Take the
querystatement as an example: when you usemysqli_query(connection, sql_statement), you must specify the resource. -
The following example shows how to use MySQLi functions to connect to a database and retrieve the value of a specific field:
$conn = new mysqli('localhost', 'user', 'password', 'data_base'); // Use the 'new' operator. The last parameter directly specifies the database. $conn->select_db('data_base'); // If the database was not specified in the previous line, run this command to select it. $result = $conn->query('select * from data_base'); $row = $result->fetch_row(); // Fetch a single row of data echo $row[0]; // Output the value of the first field
-
Can I create multiple databases on Cloud Web Hosting?
No. A Cloud Web Hosting instance has only one preinstalled business database, and its name uses the XXX_db format. You can create objects such as tables and views in this database, but you cannot add databases.
In the database list on the Database Information page of the Web Hosting console, information_schema is displayed in addition to the business database. information_schema is a system database that MySQL provides by default. It stores metadata such as table names and column names, is read-only, and cannot store business data. If you create a table in information_schema or run CREATE DATABASE, the operation fails with ERROR 1044 (42000): Access denied.
If your workloads require multiple databases, deploy your own MySQL instance on an Elastic Compute Service (ECS) instance.
Manage a Web Hosting database
When you purchase a Web Hosting instance, Alibaba Cloud pre-installs a database of the type that you select. In the Web Hosting console, you can reset the database password, change the database type, or back up the database. You can also use Data Management Service (DMS) to maintain tables and data in the database. For more information, see Web Hosting database overview.
You can manage your database by using the following tools:
-
(Recommended) Data Management Service (DMS): DMS is an Alibaba Cloud service that integrates data management, structure management, user authorization, security auditing, data trending, and data tracking. Use the web version of DMS to log on to your database. For more information, see Log on to a database by using the web version of DMS.
-
Navicat for MySQL: An ideal solution for MySQL development and management. Use this application to import and export data for your MySQL database. For more information, see Import an SQL file by using Navicat for MySQL and Export data from a database table by using Navicat for MySQL.
-
SQL Server Management Studio (SSMS): An integrated environment for managing any SQL infrastructure. Use SSMS to import and export data for your SQL Server database. For more information, see Import data into a SQL Server database by using SSMS and Export data from a SQL Server database by using SQL Server Management Studio.
Check used database space
This section uses a MySQL database as an example. Follow these steps:
-
Log on to the Web Hosting console.
-
Check the database space usage.
-
On the Site Information page:
On the Site Information page, view the space usage in the Website Information section.
This field displays the usage percentage and the amount of used space.
-
On the Database Information page:
Click Database Information on the left. On the Database Information page, view the space usage in the Data Space column.
-
Expand database space
If you need more database space, use one of the following methods to expand it.
-
Upgrade your Web Hosting instance: To get a database space of up to 1 GB, upgrade your instance. For more information, see Upgrade a Web Hosting instance.
-
Purchase additional database space: If you need more space than is pre-installed or more than 1 GB, purchase additional space. For more information, see Increase the database space of an instance.
Modify connection strings for ASP and ASP.NET
After manually migrating website data or resetting the database password, you must update the database connection string in your website's configuration file.
For websites written in ASP or ASP.NET, the database connection string is typically stored in a configuration file such as Conn.asp or Web.Config. The following code shows an example from a Conn.asp file:
set Conn=server.CreateObject("ADODB.CONNECTION")
StrConn="Provider=SQLOLEDB;Data Source=Web Hosting Database Endpoint,Port Number;User ID=Web Hosting Database Username;Password=Web Hosting Database Password;Initial Catalog=Web Hosting Database Name"
Conn.open StrConn
If your database information changes, you must replace the placeholder values in the code example with your new database credentials. For more information about how to obtain your database information, see Obtain and configure database information.
Database import failures
Symptom:
Importing a local SQL file, CSV file, or a .bak file for SQL Server into your Web Hosting database fails.
Possible causes:
-
Cause 1: The import file is too large.
-
Cause 2: The web version of DMS is outdated and does not support the import.
Solution:
-
For Cause 1, use a third-party database client, such as Navicat for MySQL or SQL Server Management Studio, to connect to your database and import the data. For more information, see Import an SQL file by using Navicat for MySQL or Import data into a SQL Server database by using SSMS.
-
For Cause 2, log on to your database again by using the New DMS Portal and retry the import.
ImportantTo log on to the new version of DMS, you must have an Alibaba Cloud account. If you purchased your Web Hosting instance through a reseller, contact the reseller to transfer the account to you. For more information, see Transfer an account.
Maximum connections reached
Symptom:
A connection to your Web Hosting database fails with an error similar to User bdm2569**** already has more than 'max_user_connections' active connections. This error indicates that the database has reached its maximum number of user connections.
Possible cause:
Your website application may have issues such as a slow query or connections that are not properly released.
Solution:
-
Modify your application code to improve query performance or to ensure that database connections are properly released.
-
Restart the Web Hosting server. For more information, see Restart a Web Hosting or Advanced Web Hosting instance.
ImportantThe server restart takes about 15 minutes. During this time, any operations you perform will not take effect. Wait for the restart to complete before performing other actions.
-
Try to connect to the Web Hosting database again.
-
If the connection is successful, the issue is resolved.
-
If the connection still fails, submit a ticket for assistance.
-