Linux下MySQL的彻底卸载和安装配置字符集_MySQL
Linux下MySQL的彻底卸载和安装配置字符集
前言:
Linux环境下MySQL的安装和配置在网上已经有很多教程了。之所以写这篇文章是因为在配置字符集的时候找了网上的一些教程发现并不能用导致折腾了一阵子。下面的教程均是亲自实践。MySQL的彻底卸载
首先查看一下自己是否已经安装了MySQL。代码如下:ps -aux|grep mysql

关于mysql的彻底卸载有很多方法,人工去卸载和删除冗余文件比较麻烦,只需依次执行以下三条指令即可:
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
这里一定要注意你的Mysql版本!
MySQL的安装
最简单的安装方式就是命令行方式,依次输入一下代码即可:sudo apt-get install mysql-server sudo apt-get install mysql-client
在安装server时会提示你设置root的密码。

MySQL字符集的配置
首先我们在终端打开mysql:mysql -uroot -p
然后输入密码即可进入mysql

然后我们输入下面的查询语句来查看默认的字符集设置:
show variables like '%character%';
我们将看到一下结果:

可以看出我们的character_set_database和character_set_server两处还未设置成utf8(或者GBK)。 下面我们只需要在mysql的配置文件修改即可。退出mysql之后在命令行输入以下代码编辑配置文件:
sudo vim /etc/mysql/my.cnf
sudo gedit /etc/mysql/my.cnf
下面只需要在两处修改即可!但要注意mysql5.5以下版本和5.5以上版本有一处不同,一定要注意自己的版本! mysql5.5以下版本修改如下: 【client】 default-character-set = utf8 【mysqld】 default-character-set = utf8
mysql5.5以上版本修改如下: 【client】 default-character-set = utf8 【mysqld】 character-set-server = utf8


接下来,重启mysql使配置文件生效: 方式有两种: 方式1:
sudo /etc/init.d/mysql restart

sudo service mysql restart

接下来进入mysql,再来看一下字符集设置:

可以看到除了system之外均该为了utf8.
注意
改字符集之前建立的数据库内的数据仍是中文乱码,这时我们备份一下数据新建即可。
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of how to modify the character set of Oracle database Oracle database is a powerful relational database management system that supports multiple character sets, including Simplified Chinese character set, Traditional Chinese character set, English character set, etc. In practical applications, you may encounter situations where you need to modify the database character set. This article will introduce in detail the method of modifying the Oracle database character set and provide specific code examples for readers' reference. 1. Check the current database character set. Before modifying the database character set, you first need to check the current database character set.

What are the tips for learning MySQL’s character set and collation settings? As a popular relational database management system, MySQL has very important character set and collation settings when processing data. Properly setting character sets and collation rules can ensure data integrity and consistency, while also improving query and sorting efficiency. This article will introduce some tips for learning MySQL character set and collation settings, and provide corresponding code examples. 1. Character set setting skills to view the current character set settings. Use the following command to view the current character set settings.

Title: Oracle Database Character Set Modification Steps and Precautions In the Oracle database, the character set is a very important setting, which determines the character types and encoding methods that can be supported by the data stored in the database. Sometimes, we need to modify the character set to adapt to new business needs or solve some data storage problems. This article will introduce in detail the steps and precautions for modifying the Oracle database character set, and will also provide specific code examples. 1. Character set modification steps: 1. Back up the database: before doing any data

MySql is a very popular database management system, especially suitable for large-scale data storage and processing. However, when using MySql, we often encounter the problem of Chinese garbled characters. This is because the character set and collation of MySql are not set correctly. The following will introduce how to solve the problem of Chinese garbled characters. 1. MySql’s character set and collation rules MySql supports multiple character sets and collation rules. The character set determines which characters can be stored in the database, and the collation determines how these characters are sorted and compared.

The character set setting in Oracle database is very important for data storage and retrieval. Correctly setting the character set can ensure the correctness and integrity of the data. In actual applications, sometimes due to some uncontrollable factors, character set mismatch may lead to garbled characters. This article will introduce in detail how to modify the character set in the Oracle database, and give specific methods and code examples to repair garbled characters. 1.Oracle character set modification method 1.1 To view the current character set in the Oracle database, you can use the following

In golang, validating a specific character set using regular expressions is a common task. This task involves the problem of finding out whether a specific string of characters is present in a set of characters. In this article, I will show you how to validate a specific character set using regular expressions in golang. First, to use regular expressions in golang, you need to import the regular expression package. In golang, the standard regular expression package is regexp. You can use the following code to import: import(&quo

MySQL is a widely used relational database management system. In order to support character sets and collation rules between different languages and cultures, MySQL provides multiple character set and collation settings. Character set and collation are very important concepts in MySQL and play a vital role in the data storage and query process. Let's take a closer look at the character sets and collation rules in MySQL. 1. Character set The character set in MySQL determines how data is stored in the database. Common character sets include A

This article will explain in detail the name of the character set returned by PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. 1. Character set in PHP The character set in PHP is used to represent a collection of letters, numbers and symbols used in text data. It defines how byte sequences are mapped to character values. PHP supports multiple character sets, including: ASCII: American Standard Code for Information Interchange, containing 7-bit characters and used in text-based systems. UTF-8: Universal Character Set Transformation Format - 8-bit, a variable-length character set widely used in modern systems. UTF-16: Universal Character Set Transformation Format - 16 bits, a fixed-length character set used to represent large numbers of characters
