Databases 4 min read

How to Fully Uninstall, Install, and Configure MySQL Character Set on Linux

This step‑by‑step guide shows how to completely remove any existing MySQL installation on Linux, reinstall it, and correctly configure the server and client character sets to UTF‑8, including version‑specific settings and verification.

21CTO
21CTO
21CTO
How to Fully Uninstall, Install, and Configure MySQL Character Set on Linux

Preface

Installing and configuring MySQL on Linux is common, but many tutorials miss proper character set setup; this guide shares a hands‑on solution.

Complete MySQL removal

Check if MySQL is installed: ps -aux|grep mysql If installed, purge it with three commands:

sudo apt-get autoremove --purge mysql-server-5.5
sudo apt-get remove mysql-common
dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P

Be sure of your MySQL version before running.

MySQL installation

sudo apt-get install mysql-server
sudo apt-get install mysql-client

Configuring MySQL character set

Open MySQL: mysql -uroot -p Check current character set variables: show variables like '%character%'; The result shows character_set_database and character_set_server are not set to UTF‑8.

Edit the configuration file: sudo vim /etc/mysql/my.cnf Or use gedit if vim is unavailable: sudo gedit /etc/mysql/my.cnf For MySQL 5.5 and below:

[client]
default-character-set = utf8
[mysqld]
default-character-set = utf8

For MySQL 5.5 and above:

[client]
default-character-set = utf8
[mysqld]
character-set-server = utf8

Restart MySQL (choose one): sudo /etc/init.d/mysql restart or

sudo service mysql restart

After restart, verify the character set; all databases except system should now use UTF‑8.

Note

Databases created before changing the character set may contain garbled Chinese characters; back up the data and recreate the databases after the configuration change.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxmysqlInstallationCharacter SetDatabase Configuration
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.