Home Database Mysql Tutorial 简单解决Windows中MySQL的中文乱码与服务启动问题_MySQL

简单解决Windows中MySQL的中文乱码与服务启动问题_MySQL

May 27, 2016 pm 01:45 PM
mysql windows Chinese Garbled characters Serve

中文乱码问题
当我第一次接触mysql,首先让我难受的是mysql的乱码问题,百度上也有许多有关的解决方案,不过作为亲身受害者,我想很有必要贴出我的心声:
1.关于mysql的字符集处理
mysql在标识数据时采取二进制字符和非二进制字符格式,前者主要用来标识图片,声音,后者就完成剩余的所有功能,而对于后者,就存在字符集设置问题。
我们知道数据库是老外搞出来的,他们在设计的时候并没有考虑到编码格式的问题,在计算机流行的现代每个国家为了支持本国的语言,都推出了自己本国的编码格式,下面利用mysql命令列出世界上所有的编码:

2016310143101531.jpg (648×726)

其中的GBK、gb2312、big5是中国的编码
GBK:支持21000多个汉字,包括简体和繁体,占2个字节
gb2312:支持6700多个汉字,占2个字节
big5:支持繁体字符集,主要是支持香港、台湾那边的字符,繁体,13000多汉字,2个字节
国际标准化组织为了统一格式,创建了UTF8编码,也就是unicode编码的一种格式,称为万国码,支持世界上的所有语言具体解决方案:
首先利用命令行,查看字符集:

2016310143124283.png (648×430)

解释下乱码原理:
当我们链接mysql数据库时,实际上要经过下面几个步骤:
客户端->链接端->数据库字段端->返回端
就是上面的贴图中的

character_set_client
character_set_connection
character_set_database
character_set_result
Copy after login

乱码问题出现这几个步骤中,只要其中某个步骤出错,就会出现乱码
当我们用程序在外部链接mysql 数据库时,客户端就是我们的程序软件,所以要将客户端设置成GBK或者gb2312,链接时设置为UTF8或者GBK,数据库设置为gbk或utf8
返回设置成GBK,这样一般就不会出现中文乱码了
如下图所示:
你可以通过命令行设置:
如果不考虑注入问题,你可以采取以下方法:

set names gbk ;
Copy after login

这条命令设置了客户端、连接端、返回端均为GBK;

2016310143321628.png (640×416)

你也可以逐个设置:
在创建库的时候设置字符集:
利用命令:

create database mydatabase default character set utf8;
Copy after login

2016310143356799.png (640×221)

在创建表的时候指定表的字符集:
利用命令:

create table user(name char(30) character set gbk) default character set gbk;
Copy after login

2016310143411912.png (635×79)

还有如下设置:
设置结果集:

set character_set_results=gbk;
Copy after login

设置连接字符集:

set character_set_connection=gbk;
Copy after login

因为我们现在是学习阶段,不考虑内存容量问题,统一设置为UTF8,如果你的程序只支持汉语,你的作品向外发行最好选择GBK编码。。。。。
如果你按照上面的方法做还是发现程序运行有问题,请检查您的程序是否也是UNICODE编码,我以前就是因为这个原因。


启动服务问题
我现在假设您在安装mysql数据库的时候建立了登录用户和密码(mysql是免费的可以到官网下载)
安装完成的mysql数据库是开机自动运行的,如果您的mysql数据库服务不小心被关闭,可以采取以下解决方案:
方案1:在桌面计算机图标上单击鼠标右键,
管理->服务和应用程序->服务 然后在列表中找到mysql服务项,单击鼠标右键执行“启动”,当然你也可以在这里停止mysql服务。

2016310143434856.jpg (778×449)

方案2:
打开cmd(命令行),执行命令:

net start mysql55
Copy after login

注意:这里的mysql55是我的PC上的MYSQl数据库服务名,具体要按照自己PC的数据库服务名执行。。。这个服务名是你安装mysq数据库指定的服务名。

2016310143500402.png (675×439)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

See all articles