简单解决Windows中MySQL的中文乱码与服务启动问题_MySQL
中文乱码问题
当我第一次接触mysql,首先让我难受的是mysql的乱码问题,百度上也有许多有关的解决方案,不过作为亲身受害者,我想很有必要贴出我的心声:
1.关于mysql的字符集处理
mysql在标识数据时采取二进制字符和非二进制字符格式,前者主要用来标识图片,声音,后者就完成剩余的所有功能,而对于后者,就存在字符集设置问题。
我们知道数据库是老外搞出来的,他们在设计的时候并没有考虑到编码格式的问题,在计算机流行的现代每个国家为了支持本国的语言,都推出了自己本国的编码格式,下面利用mysql命令列出世界上所有的编码:
其中的GBK、gb2312、big5是中国的编码
GBK:支持21000多个汉字,包括简体和繁体,占2个字节
gb2312:支持6700多个汉字,占2个字节
big5:支持繁体字符集,主要是支持香港、台湾那边的字符,繁体,13000多汉字,2个字节
国际标准化组织为了统一格式,创建了UTF8编码,也就是unicode编码的一种格式,称为万国码,支持世界上的所有语言具体解决方案:
首先利用命令行,查看字符集:
解释下乱码原理:
当我们链接mysql数据库时,实际上要经过下面几个步骤:
客户端->链接端->数据库字段端->返回端
就是上面的贴图中的
character_set_client character_set_connection character_set_database character_set_result
乱码问题出现这几个步骤中,只要其中某个步骤出错,就会出现乱码
当我们用程序在外部链接mysql 数据库时,客户端就是我们的程序软件,所以要将客户端设置成GBK或者gb2312,链接时设置为UTF8或者GBK,数据库设置为gbk或utf8
返回设置成GBK,这样一般就不会出现中文乱码了
如下图所示:
你可以通过命令行设置:
如果不考虑注入问题,你可以采取以下方法:
set names gbk ;
这条命令设置了客户端、连接端、返回端均为GBK;
你也可以逐个设置:
在创建库的时候设置字符集:
利用命令:
create database mydatabase default character set utf8;
在创建表的时候指定表的字符集:
利用命令:
create table user(name char(30) character set gbk) default character set gbk;
还有如下设置:
设置结果集:
set character_set_results=gbk;
设置连接字符集:
set character_set_connection=gbk;
因为我们现在是学习阶段,不考虑内存容量问题,统一设置为UTF8,如果你的程序只支持汉语,你的作品向外发行最好选择GBK编码。。。。。
如果你按照上面的方法做还是发现程序运行有问题,请检查您的程序是否也是UNICODE编码,我以前就是因为这个原因。
启动服务问题
我现在假设您在安装mysql数据库的时候建立了登录用户和密码(mysql是免费的可以到官网下载)
安装完成的mysql数据库是开机自动运行的,如果您的mysql数据库服务不小心被关闭,可以采取以下解决方案:
方案1:在桌面计算机图标上单击鼠标右键,
管理->服务和应用程序->服务 然后在列表中找到mysql服务项,单击鼠标右键执行“启动”,当然你也可以在这里停止mysql服务。
方案2:
打开cmd(命令行),执行命令:
net start mysql55
注意:这里的mysql55是我的PC上的MYSQl数据库服务名,具体要按照自己PC的数据库服务名执行。。。这个服务名是你安装mysq数据库指定的服务名。

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

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

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



Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

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.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

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.

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.

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.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.
