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.
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 -PBe sure of your MySQL version before running.
MySQL installation
sudo apt-get install mysql-server
sudo apt-get install mysql-clientConfiguring 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 = utf8For MySQL 5.5 and above:
[client]
default-character-set = utf8
[mysqld]
character-set-server = utf8Restart MySQL (choose one): sudo /etc/init.d/mysql restart or
sudo service mysql restartAfter 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
