ubuntu下python页面乱码有关问题及解决(pycharm+mysql+ubuntu)
ubuntu下python页面乱码问题及解决(pycharm+mysql+ubuntu) there is no doubt that 这是编码问题引起的,应该确保mysql,pycharm和浏览器的编码三码合一。 1,在每个python页开头加上一行“# -*- coding: utf-8 -*-” 类这样:#!/usr/bin/python # -*- codin
ubuntu下python页面乱码问题及解决(pycharm+mysql+ubuntu)there is no doubt that 这是编码问题引起的,应该确保mysql,pycharm和浏览器的编码三码合一。
1,在每个python页开头加上一行“# -*- coding: utf-8 -*-”
类似这样:#!/usr/bin/python
# -*- coding: utf-8 -*-
2,修改pycharm的编码:
setting -> File Encoding -> 所有 编码方式都改成UTF-8(网上一些教程说IDE Encoding要改成GBK,是因为在windows下默认编码是GBK,而ubuntu下是utf8)
3,修改mysql的编码:
查看你的mysql编码:登录后,输入命令show variables like '%char%' 如:mysql>show variables like '%char%' 然后就会显示mysql的默认编码:
可以手动用命令set @@character_set_client=utf8来修改,但是似乎不是永久的,建议直接修改配置文件/etc/mysql/my.cnf文件
找到[client]和[mysql]在它们下面加入这句default-character-set=utf8,
找到[mysqld],在它下面加这段
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
保存退出。
重启mysql。在shell命令行下输入sudo service mysql restart
重启后登录mysql查看编码(命令show variables like '%char%'),会发现都变成了utf-8,除了filesystem(我的character_set_database还是GBK,不过似乎没什么影响)
网上找到的修改mysql配置文件的教程都是说在[mysqld]下加入default-character-set=utf8和 init_connect='SET NAMES utf8'这两句,但是实践证明加入后无法重启mysql。读者不妨可以试试。
4,修改浏览器编码。ubuntu下一般是用火狐浏览器,修改方法如下:
编辑 -》首选项 -》内容 -》字体和颜色的“高级”按钮 -》默认字符编码改为UTF8
如果以上都保证无误,还是出现乱码问题,可以尝试检查:
1,火狐浏览器页面上,右键查看页面信息 -》常规 -》看看编码是不是utf8,如果不是的话:在火狐浏览器左上角 :查看-》字符编码 -》utf8
2,如果页面字符编码是utf8,应确保mysql里存的数据不是乱码 : 登录进mysql,查看你的表里的数据是否是乱码,mysql -> select * from yourTableName,如果是乱码,用insert into语句插入中文,后在浏览器看看是否能正常显示。

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.


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

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment