MySQL 8.0 vs 5.7: New Features & Full Migration Guide

1. Introduction

Overview of MySQL

MySQL is the most widely used open-source relational database management system (RDBMS) worldwide. It is an essential component for web applications and enterprise systems, supported by many engineers and database administrators. Moreover, upgrading MySQL not only improves system stability and performance but also plays a crucial role in leveraging new features.

Why Focus on the Differences Between MySQL 5.7 and 8.0

The mainstream MySQL versions, 5.7 and 8.0, have many differences. Understanding these differences is vital for making the right version choice and planning a migration. For example, MySQL 8.0 changes the default character set and improves performance, while some features are deprecated, creating points that require attention during migration. In this article, we explain the main differences and new features of MySQL 5.7 and 8.0, and provide migration cautions and practical advice. We also include an FAQ section that addresses common questions readers may have. The goal is to deliver a resource packed with useful information for developers and database administrators considering a MySQL upgrade.

2. Major Differences Between MySQL 5.7 and 8.0 (Beginner Overview)

Changing the Default Character Set

In MySQL 5.7, the default character set was “latin1”, but in 8.0 it has been changed to “utf8mb4”. utf8mb4 fully supports emojis and special characters, greatly improving character set compatibility. This provides a reliable environment for international websites and applications. Example:
-- Emoji data that may cause an error in MySQL 5.7
INSERT INTO test_table (text_column) VALUES ('😊'); 
In 8.0, such emoji data can be stored without issues.

New Features Added

MySQL 8.0 includes many new features that streamline the work of developers and database administrators. Below are some of the most important ones.
  1. Enhanced JSON Functionality
  • Searching and manipulating JSON data has become more intuitive.
  • Example: Easily extract specific values from JSON data. sql SELECT JSON_EXTRACT(json_column, '$.key') FROM test_table;
  1. Introduction of Window Functions
  • Window functions have been added to streamline data analysis.
  • Example: Query to calculate sales ranking for each customer sql SELECT customer_id, sales, RANK() OVER (ORDER BY sales DESC) AS rank FROM sales_table;

Deprecated and Removed Features

In MySQL 8.0, several features have been deprecated or removed. Here are some examples.
  • query_cache Removal It has been deprecated to improve performance. Instead, indexing and application-side cache management are recommended.
  • Discontinuation of Old Encryption Methods Old authentication methods have been removed to enhance security.

Performance Improvements

MySQL 8.0 significantly improves query processing speed and index management, resulting in much better performance, especially in environments handling large amounts of data. Specific examples:
  • Heatmap-based Index Management: Allows efficient removal of rarely used indexes.
  • InnoDB Optimization: Accelerates transaction processing.
-- Index optimization example
ALTER TABLE sales_table ADD INDEX (sales_amount);

3. In‑Depth Look at Differences Between MySQL 5.7 and 8.0 (For Intermediate/Advanced Users)

Details of the Default Character Set

MySQL 8.0 changes the default character set to utf8mb4. This greatly improves internationalization support for data. For example, multibyte character sets needed to store emojis and special characters are supported by default. Impact in Production:
  • Character Set Compatibility: When migrating from 5.7 to 8.0, if existing databases use latin1 or other character sets, you need to consider changing the character set during migration.
  • Performance Improvements: Using utf8mb4 can make some string comparisons more efficient, but you should verify the performance impact on large databases in advance.
-- Example of changing to utf8mb4
ALTER TABLE sample_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Enhanced JSON Features

MySQL 5.7 introduced the JSON data type for the first time, and MySQL 8.0 adds even more powerful features. This makes managing and manipulating structured data easier and streamlines application development. Key Improvements:
  1. JSON_TABLE function Allows JSON data to be transformed into a tabular format, making it easy to query complex JSON data.
   SELECT * FROM JSON_TABLE(
       '[{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]',
       '$[*]' COLUMNS (
           id INT PATH '$.id',
           name VARCHAR(50) PATH '$.name'
       )
   ) AS jt;
  1. Index Optimization Creating indexes on JSON data is now possible, improving query performance.
   CREATE INDEX json_index ON test_table (JSON_EXTRACT(json_column, '$.key'));

Performance and InnoDB Improvements

MySQL 8.0 includes major optimizations to the InnoDB engine, improving transaction processing speed and making large‑scale data handling more efficient. Key Enhancements:
  1. Doublewrite Buffer Introduction Improves data crash resilience and enhances disk I/O efficiency.
  2. Persistent Metadata Addition Storing table definitions and index information on disk improves performance after a restart.
Example:
-- Example of index optimization
ALTER TABLE sales_table ADD INDEX (sales_amount);

Introduction of Window Functions

MySQL 8.0 adds window functions, making data analysis easier. With window functions, you can efficiently perform complex operations such as aggregations and ranking. Typical Use Cases:
  • Calculate cumulative sales per customer
  • Compute rankings and positions
Example: Calculating Cumulative Sales
SELECT customer_id, sales, SUM(sales) OVER (PARTITION BY customer_id ORDER BY sales_date) AS cumulative_sales
FROM sales_table;

Deprecated Features and Migration Considerations

MySQL 8.0 has removed or deprecated several features. Understanding these is essential to avoid issues during migration.
  • Removed Features
  • query_cache: Removed to improve performance.
  • Old authentication methods: Deprecated to enhance security.
  • Migration Considerations
  • You need to identify queries or applications that use deprecated features in advance and consider alternatives.

4. Migration Considerations

Checking Compatibility

Before migrating, it is important to review the incompatible changes and deprecated features in MySQL 8.0. Pay particular attention to the following points.
  1. Changes to Reserved Words MySQL 8.0 adds new reserved words that may conflict with existing column or table names. You need to check and rename them in advance. Example: GROUPS and WINDOW became reserved words in 8.0.
   -- Example rename to avoid issues
   ALTER TABLE example_table RENAME COLUMN groups TO user_groups;
  1. Use of Deprecated Features Queries or settings that worked in 5.7 may be deprecated or removed in 8.0. For example, query_cache has been removed in 8.0. Consider using application-level caching as an alternative.
  2. Changes to Character Set and Collation MySQL 8.0 changes the default character set to utf8mb4. If existing tables use latin1 or other character sets, compatibility issues may arise during migration.
   -- Example of changing character set
   ALTER TABLE my_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Importance of Data Backups

There is a risk of data loss or corruption during migration. Therefore, be sure to take a backup beforehand. Recommended Backup Methods:
  • Using mysqldump
  mysqldump -u root -p --all-databases > backup.sql
  • Physical backup (using tools like Percona XtraBackup).
After taking a backup, restore it in the target environment and test to ensure the data migrates correctly.

Testing in a Test Environment

Migration should always be performed first in a test environment, not in production. In the test environment, follow these steps to identify issues.
  1. Data Restore Restore the backup in the test environment and simulate the migration.
  2. Application Verification After migration, verify that the application works correctly on MySQL 8.0, paying particular attention to SQL query compatibility and performance.
  3. Load Testing Conduct load testing on the migrated database, simulating real traffic to identify performance bottlenecks.

Planning the Migration

A detailed plan is essential for a successful migration. Use the following migration steps as a reference when planning.
  1. Current State Analysis
  • Understand the current MySQL environment’s configuration and usage.
  • Check for deprecated features and reserved word conflicts.
  1. Preparing Migration Tools
  • Use MySQL’s official mysql_upgrade tool to smoothly upgrade the database.
  1. Phased Migration
  • First perform the migration in a development environment, then move to staging, and finally to production.
  1. Post-Migration Optimization
  • Rebuild indexes and perform performance tuning.
   ANALYZE TABLE my_table;
   OPTIMIZE TABLE my_table;

Troubleshooting

If problems arise during migration, resolve them using the following methods.
  1. Check Error Logs Review MySQL logs to pinpoint the cause of errors.
   tail -f /var/log/mysql/error.log
  1. Use Compatibility Settings In MySQL 8.0, you can temporarily change sql_mode to ensure compatibility.
   SET sql_mode='NO_ENGINE_SUBSTITUTION';
  1. Leverage Official Documentation Consult MySQL’s upgrade guide and FAQ for solutions.

5. Migration Procedure Guide

Migration Preparation

  1. Check the current version Check the current MySQL version before migration. This helps with using the mysql_upgrade tool and verifying compatibility.
   mysql --version
  1. Check for deprecated features Identify deprecated features and settings that could affect the migration. Create a list using the official “MySQL 8.0 Upgrade Guide”.
  2. Data backup Obtain a full backup to keep the data safe. Recommended methods are as follows:
  • mysqldump command use: bash mysqldump -u root -p --all-databases > backup.sql
  • Physical backup (using Percona XtraBackup, etc.).
After taking the backup, restore it in the target environment and test to ensure the data migrates correctly.

Migration Steps

  1. Install MySQL 8.0 Install MySQL 8.0 on the target server. Installation steps vary by OS; the following is an example for Ubuntu:
   sudo apt update
   sudo apt install mysql-server
  1. Verify configuration files Check the my.cnf (or my.ini) file and update the settings.
  • Remove deprecated options
  • Set the new character set (utf8mb4)
   [mysqld]
   character-set-server=utf8mb4
   collation-server=utf8mb4_unicode_ci
  1. Import data Import the data using the backup file you obtained.
   mysql -u root -p < backup.sql
  1. Run the mysql_upgrade tool After upgrading to MySQL 8.0, run the mysql_upgrade tool to update the databases to the latest format.
   mysql_upgrade -u root -p

Post-Migration Optimization

  1. Rebuild indexes Rebuild indexes to optimize for the new InnoDB engine.
   ALTER TABLE table_name ENGINE=InnoDB;
  1. Check query performance After migration, test the main queries used by the application and adjust indexes or settings as needed.
   EXPLAIN SELECT * FROM table_name WHERE column_name = 'value';
  1. Monitor logs For several days after migration, monitor error logs and slow query logs to detect issues early.
   tail -f /var/log/mysql/error.log

Testing and Validation

After migration, perform the following tests to verify operation.
  1. Verify application functionality Ensure the application runs correctly and all queries behave as expected.
  2. Load testing Conduct load tests that simulate real traffic to evaluate performance and stability.
  3. Check data integrity After migrating from 5.7 to 8.0, verify that data is retained correctly. Pay special attention to issues related to character sets and collations.

Troubleshooting Measures

If problems arise during or after migration, consider the following actions.
  1. Restore from backup If the issue cannot be resolved, consider restoring the backup to revert to the previous environment.
  2. Consult official support Use MySQL’s official upgrade guide and support resources to find solutions.
  3. Share error details Posting error information on forums or developer communities can help you obtain solutions.

6. FAQ (Frequently Asked Questions)

Q1: When does support for MySQL 5.7 end? A1: Official support for MySQL 5.7 ended at the end of October 2023. Since security updates and bug fixes will no longer be provided, we recommend planning a migration to MySQL 8.0 as early as possible. Q2: Is migration to MySQL 8.0 mandatory? A2: Migration is not mandatory, but it is recommended for the following reasons.
  • MySQL 8.0 offers improved security and performance.
  • New features (e.g., enhanced JSON capabilities and window functions) improve development efficiency.
  • With MySQL 5.7’s support ending, you can reduce security risks.

Q3: Will data compatibility be maintained during migration?

A3: In general, data compatibility is maintained. However, attention is needed in the following cases:
  • If the character set uses latin1 or an older collation, there is a risk of garbled text after migration.
  • If you are using deprecated or removed features, errors or unexpected behavior may occur.
We strongly recommend verifying in a test environment before migration to ensure there are no issues. Q4: Can you revert to the original version after migration? A4: Rolling back data that has been migrated to MySQL 8.0 to MySQL 5.7 is very difficult. Because MySQL 8.0 changes the internal data structure, compatibility is not easily maintained. Therefore, you must take a backup before migration and be prepared for any issues.

Q5: How much time does migration take?

A5: The time required for migration varies depending on the size of the database and environment, but the following factors affect it:
  • Database size (larger data volumes take more time).
  • Server performance and network speed.
  • Time for testing in a test environment and handling issues.
A small database may take a few hours, while a large system can take several days.

Q6: What are the key changes in MySQL 8.0 that require special attention?

A6: There are several important changes:
  • The default character set has changed to utf8mb4, which may cause character set issues during migration.
  • query_cache has been removed, and the caching configuration method has changed.
  • New reserved words (e.g., GROUPS and WINDOW) have been added, which may cause conflicts with existing tables or queries.

Q7: Can performance degrade after migration?

A7: If you follow the proper migration steps, MySQL 8.0’s performance usually improves. However, performance may temporarily degrade in the following cases:
  • Improper index configuration.
  • Inefficient queries that become apparent after migration.
  • New settings that are not optimized.
We recommend rebuilding indexes after migration and checking query performance.

Q8: What security enhancements does MySQL 8.0 have?

A8: MySQL 8.0 strengthens the following security features:
  • Enhanced authentication method: caching_sha2_password is now the default, raising the security level.
  • Expanded data encryption: InnoDB tablespace encryption has been introduced.
  • Login attempt limits: You can set a limit on failed login attempts, adding a mechanism to prevent unauthorized access.

Q9: Should you outsource the migration to MySQL 8.0?

A9: Decide based on the size of the database and your internal technical expertise. Small environments can often be handled in-house, but for large systems or environments requiring high availability, hiring experts can reduce risk.

7. Summary

Benefits of Migrating to MySQL 8.0

  1. Improved Performance
  • Optimizations in the new InnoDB engine have significantly improved transaction processing and query execution speed.
  1. Addition of New Features
  • Enhanced JSON capabilities and the introduction of window functions streamline data manipulation and analysis.
  • Changing the default character set to utf8mb4 makes internationalization easier.
  1. Enhanced Security
  • Strengthened authentication methods and encryption features improve security.

Things to Watch Out for During Migration

  • Check for Deprecated and Removed Features
  • Verify items such as query_cache and old authentication methods that could affect the migration.
  • Character Set Issues
  • If you are using latin1 or other character sets, you may encounter garbled text after migration. Switching to an appropriate character set is necessary.
  • Testing in a Staging Environment
  • Before applying changes to production, simulate the migration in a test environment to resolve potential issues in advance.

Key Points for a Successful Migration

  1. Thorough Preparation
  • Analyze the current database state to identify incompatibilities and potential issues.
  • Take backups and verify the restore procedures.
  1. Migrate Incrementally
  • Proceed with migration from test to staging to production environments, addressing issues at each stage.
  1. Post-Migration Optimization
  • Rebuild indexes and adjust settings to maximize database performance after migration.

Future Outlook

MySQL 8.0 continues to evolve, and leveraging its latest features can further improve development efficiency and operational stability. In particular, using the JSON data type and window functions can bring transformative changes to many applications. We hope this article has deepened your understanding of migrating from MySQL 5.7 to 8.0, and that you now grasp the concrete steps and considerations. Execute a well-planned migration and fully capitalize on the new possibilities offered by MySQL 8.0.