如何将MariaDB数据库迁移至MySQL服务器(XAMPP环境)
Hey Ronny, sorry to hear you’re hitting snags migrating your XAMPP database to a MySQL-only web host—let’s walk through the reliable, no-manual-table-setup fixes here!
解决XAMPP到MySQL虚拟主机的数据库迁移问题
一、修正phpMyAdmin导出设置(GUI方法,最易上手)
Your syntax errors almost certainly come from including XAMPP/MariaDB-specific syntax during export. Follow these steps to generate a MySQL-compatible dump:
- Open your local XAMPP phpMyAdmin, select the database you want to migrate.
- Click the Export tab, choose the Custom export mode (skip the Quick mode—it’s too generic!).
- Scroll down to Format-specific options:
- Set "Database system or older MySQL server to maximize compatibility with" to MySQL 4.0 or higher (most web hosts support this, avoiding modern MariaDB-only features).
- Under Object creation options:
- Check "Add IF EXISTS" before DROP statements (prevents errors if any tables accidentally exist on the host).
- Uncheck any options tied to MariaDB-specific features (look for labels explicitly mentioning MariaDB).
- Under Data export options:
- Choose Complete inserts instead of Extended inserts if your host has strict packet limits (this splits long INSERTs into smaller, safer chunks).
- Set the character set to
utf8mb4(matches most modern MySQL setups and avoids encoding issues).
- Finally, confirm the export type is SQL, then click Execute to save the dump file.
导入到虚拟主机
- Log into your web host’s phpMyAdmin, create an empty database (match your local database name to avoid code config changes later).
- Go to the Import tab, upload your saved SQL file.
- Under Format-specific options, set "SQL compatibility mode" to NONE or MySQL (don’t select MariaDB).
- Click Execute—this will auto-create all tables, relationships, and populate data without manual work.
二、备选方案:用mysqldump命令行(更稳定,适合大型数据库)
If phpMyAdmin keeps failing, use XAMPP’s built-in mysqldump tool—it’s less prone to GUI-related bugs:
- Open XAMPP’s Shell (or Windows Command Prompt, navigate to your XAMPP MySQL bin folder with
cd C:\xampp\mysql\bin). - Run this command (replace placeholders with your details):
mysqldump -u root -p --compatible=mysql40 --default-character-set=utf8mb4 your_local_db_name > db_backup.sql
-u root: Your local XAMPP MySQL username (default isroot).-p: Prompts for your local MySQL password (leave blank and hit enter if you didn’t set one).--compatible=mysql40: Ensures the dump works on all standard MySQL hosts.your_local_db_name: Replace with the name of your database.
导入到虚拟主机
- If your host supports SSH, log in via terminal and run:
mysql -u host_db_username -p host_db_name < db_backup.sql
- If SSH isn’t available, upload
db_backup.sqlto your host and use their phpMyAdmin import tool (follow the same steps as the GUI method above).
三、常见故障排查
- Max allowed packet errors: If you get this, re-export with Complete inserts (splits large data chunks) or ask your host to increase the
max_allowed_packetsetting. - Permission errors: Ensure your web host’s database user has
CREATE,INSERT, andALTERpermissions (most hosts grant these automatically when creating a database). - Stored procedures/triggers missing: When exporting, check the boxes for "Export stored procedures and functions" and "Export triggers"—make sure your host’s user has permissions to create these objects too.
内容的提问来源于stack exchange,提问作者Ronny Kaufmann




