Complete uninstallation and installation of MySQL under Linux configure character set

Complete uninstallation and installation of MySQL under Linux configure character set

Foreword:

     There are many tutorials on the Internet for the installation and configuration of MySQL in the Linux environment. The reason why I wrote this article is because I found some tutorials on the Internet when configuring the character set and found that it could not be used, which caused a tossing for a while.

The following tutorials are all hands-on practice.

Complete uninstall of MySQL

First check to see if you have MySQL installed. The code is as follows:
ps -aux|grep mysql
If it is not installed, nothing will be displayed. If installed, it will display a sample such as the following information:



There are many ways to completely uninstall mysql, and it is more troublesome to uninstall and delete redundant files manually. Just run the following three commands in sequence:
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 to pay attention to your Mysql version number here .

MySQL installation

The easiest way to install is from the command line. Just enter the code one by one:
sudo apt-get install mysql-server

sudo apt-get install mysql-client

When installing the server, you will be prompted to set the root password.


MySQL character set configuration

First we open mysql in the terminal:
mysql -uroot -p

Then enter password to enter mysql


Then we enter the following query to see the default character set settings:
show variables like '%character%';

We will see the result:


It can be seen that our character_set_database and character_set_server have not been set to utf8 (or GBK).

Below we only need to change the mysql configuration file.

After exiting mysql, enter the following code on the command line to edit the configuration file:

sudo vim /etc/mysql/my.cnf
Assuming that vim is not installed, it can be opened with gedit that comes with the system:
sudo gedit /etc/mysql/my.cnf

The following only needs to be changed in two places! But pay attention to the difference between the version number below mysql5.5 and the version number above 5.5 , you must pay attention to your own version number!
The version number changes below mysql5.5 are as follows:
client
default-character-set = utf8
mysqld
default-character-set = utf8

For example, the version number changes above mysql5.5 are as follows:
client
default-character-set = utf8
mysqld
character-set-server = utf8




Next, restart mysql for the configuration file to take effect:
There are two ways:
Way 1:
sudo /etc/init.d/mysql restart
Way 2:
sudo service mysql restart


Next, enter mysql. Let's take a look at the character set settings again:


It can be seen that all except system should be utf8.

Notice

The data in the database established before changing the character set is still garbled in Chinese, then we can back up the data and create a new one.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324811568&siteId=291194637