Can I copy installed mysql from ubuntu to centos7 directly without installation?
The simple answer is NO. A more realistic answer would be not easily. If you wanted to do this &quot;the wrong way&quot;, you would do something like this:

Install the exact same version of MySQL on Ubuntu as you are running on CentOS
Copy the entire contents of your /var/lib/mysql directory from CentOS to Ubuntu
Modify all of the configuration files to ensure they are using Ubuntu's directory paths rather than those used by CentOS
Cross your fingers
Start MySQL and hope everything magically works

This is a recipe for disaster as it almost always results in more work than doing it &quot;a better way&quot;. Here is how I migrate MySQL data from one server to another:

Note: All of the following commands work on Ubuntu and MySQL.


Install MySQL on the target server:
sudo apt update
sudo apt install mysql-server


Configure MySQL:
sudo mysql_secure_installation

You will be walked through the preliminary setup for MySQL, including the option to set a password for the root account. Do note that even though you've set a password for the root MySQL user, the account is not configured to authenticate with a password when connecting to the MySQL shell. More on this later.

Create your MySQL administration account:
mysql&gt; CREATE USER 'huangxy'@'localhost' IDENTIFIED WITH mysql_native_password BY 'superSecretPassword!123';

If you will be connecting to MySQL remotely, you will need to replace localhost with %.
Important: Do not use root for all of your administration activities. It is better if you have an account specific to you, even if it has full access to the whole system. root should be used only when absolutely necessary, such as when configuring replication or fixing corrupted databases.

Give your account full access:
mysql&gt; GRANT ALL ON *.* TO 'huangxy'@'localhost' WITH GRANT OPTION;


Ensure the privileges are written:
mysql&gt; FLUSH PRIVILEGES;


Exit MySQL:
mysql&gt; exit;



With this done, now you can create a backup of the MySQL database(s) on your CentOS server. You will need two connections to do this: one to MySQL, and the other to the shell where you can use mysqldump.

Lock MySQL, preventing any updates:
mysql&gt; FLUSH TABLES WITH READ LOCK;
mysql&gt; SET GLOBAL read_only = ON;

This is done to ensure that nothing interferes with the database export.
Dump the databases to disk:
mysqldump -u root -p --routines --triggers --add-drop-database --all-databases --all-databases &gt; full_backup.sql

If the version of MySQL on CentOS is 8.0.2 or above, you can also migrate your Users along with permissions:
mysqldump -u root -p mysql user --no-create-info &gt; user_backup.sql

Note: If you are using any version of MySQL lower than 8.0.2, you cannot migrate your users with this command. Instead they will need to be created manually on the new server. This is because the mysql.user table has seen a number of schema changes over the years.
If people still need access to the previous system, you can now unlock the databases:
mysql&gt; SET GLOBAL read_only = OFF;
mysql&gt; UNLOCK TABLES;

Be sure to advise people that any changes to data in the old system will not be reflected in the new system.
Copy the database dumps to the new server
Import the databases:
sudo mysql &lt; full_backup.sql

Note: You do not need to specify -u or enter a password here because it is implied that a person with sudo access on an Ubuntu system has full permissions, therefore another password for MySQL is unnecessary.
If applicable, import the user accounts:
sudo mysql mysql &lt; user_backup.sql

Note: Because the --no-create-info option was used when writing the user data to disk, there is no risk of the table being unnecessarily dropped. If there are any schema differences, an error will be reported and you will need to manually resolve the issues.
Connect to MySQL and check that your databases are intact.
Restart MySQL just to clear the buffers:
sudo service mysql restart

So long as there are no issues with the import process, a successful restart will let you know that you're pretty much good to go.

Next Steps ...
Nothing has been said about the various configuration files that MySQL uses for its settings, and that's because it is impossible for me to offer a properly comprehensive outline of what to do. I do not know anything about your server hardware, the databases, or how the systems are used. What I can recommend is this:

Tweak the basic InnoDB settings for your hardware
Monitor the system and make incremental changes as you see fit

I would not recommend copy/pasting the .cnf files from CentOS to Ubuntu, as this would be suboptimal.
While this answer is rather long and may look complicated, it's generally the most reliable way in my experience to move from one server and/or OS to another.