Installation and configuration of character sets for MySQL in Linux many tutorials have been provided on the Internet. I wrote this article because I found some tutorials on the internet when I configured the character set and found that it could not be used. Installation and configuration of character sets for MySQL in Linux many tutorials have been provided on the Internet. I wrote this article because I found some tutorials on the internet when I configured the character set and found that it could not be used. The following tutorials are all in person. To thoroughly uninstall MySQL, first check whether MySQL has been installed. The code is as follows:
ps -aux|grep mysql
If not installed, no content is displayed. if installed, the following information is displayed:
There are many ways to thoroughly uninstall mysql. it is troublesome to manually detach and delete redundant files. you only need to execute the following three commands in sequence:
sudo apt-get autoremove --purge mysql-server-5.5sudo apt-get remove mysql-commondpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
Pay attention to your
Mysql version!
The simplest installation method for MySQL is the command line method. enter the following code in sequence:
sudo apt-get install mysql-serversudo apt-get install mysql-client
When installing the server, you will be prompted to set the root password.
To configure the MySQL character set, first open mysql on the terminal:
mysql -uroot -p
Enter the password to access mysql.
Then, enter the following query statement to view the default character set settings:
show variables like '%character%';
We will see the result:
We can see that the character_set_database and character_set_server are not set to utf8 (or GBK ). Next we only need to modify it in the mysql configuration file. After exiting mysql, enter the following code in the command line to edit the configuration file:
sudo vim /etc/mysql/my.cnf
If vim is not installed, open it with the built-in gedit:
sudo gedit /etc/mysql/my.cnf
You only need to modify the following in two places! Note that
Versions earlier than mysql5.5And
Version 5.5 or laterThere is a difference. Be sure to pay attention to your own version!
Versions earlier than mysql5.5Modify as follows :【
Client] Default-character-set = utf8 【
Mysqld]
Default-character-set = utf8
Mysql5.5 or later versionsModify as follows :【
Client] Default-character-set = utf8 【
Mysqld] Character-set-server = utf8
Next,
Restart mysqlTo make the configuration file take effect: there are two ways: Method 1:
sudo /etc/init.d/mysql restart
Method 2:
sudo service mysql restart
Next, go to mysql and check character set settings:
We can see that
Except systemThis is utf8. note:
Databases created before changing the character setThe data in is still garbled in Chinese characters. now we can back up the data and create a new one.