来源:http://xiaoych.javaeye.com/blog/148704 算来我也是mysql的忠实用户了,从mysql 3 的时候就开始用mysql,直到现在开始使用5.1版本,看到mysql一点一点的变化,感觉mysql功能越来越强大,真是是我们这种用不起oracle用户的福音啊! 如果没有记错的话,
来源:http://xiaoych.javaeye.com/blog/148704
算来我也是mysql的忠实用户了,从mysql 3 的时候就开始用mysql,直到现在开始使用5.1版本,看到mysql一点一点的变化,感觉mysql功能越来越强大,真是是我们这种用不起oracle用户的福音啊!
如果没有记错的话,mysql4.0升级到4.1以后,就增加了字符集这个概念。从mysql4.0及以下的版本,迁移到mysql4.1及其以上的版本就会出现中文字符出现乱码的问题。由于以前mysql的编码是latin1 SW (好像是瑞典字符集——mysql是由瑞典人开发的,估计当时没有考虑国际化的问题),现在我们用的编码一般是gbk或者utf8。那么以前latin1编码的表中的中文怎么迁移到gbk或者utf8编码的表中呢?直接更改表的编码是没有任何作用的,参考了一些资料,说是mysql在更改表编码的时候,不会对表中现有数据进行转码。
网上有很多怎么进行转码的资料和程序,感觉都不是很方便。比较BT的就是用PHP,一行一行的从mysql的源表中读出来,再利用PHP进行转码,然后再查到目标表中。想想这样做确实有用。但是性能惨不忍睹……小表还可以这么做,要是上百万行记录的表,非等上几个小时不可,实在太浪费时间。
好了,前面都是废话,俺就贡献一下俺的研究吧:
首先,到mysql/bin 下面,利用mysqldump这个工具,执行以下命令:
mysql代码
mysqldump --u=root -p --default-character-set=latin1 --set-charset=utf8 --skip-opt --result-file=c:/mytable.sql mydb mytable
其中:root 为数据库登录名, latin1 为源表(就是想进行转码的表)的编码, utf8 为想转换成的编码, c:/mytable.sql 为导出的数据的存放文件(临时用), mydb是源表所属的数据库(schema),mytable 就是源表名了
执行这条命令,会提示输入密码,输入正确的密码以后,就开始导出数据了。等到数据全部导出以后,可以用ue等工具打开,这时可以看到这些数据的编码已经转变了。
然后需要对这个文件进行一点点更改。在文件的最开头有一个建表语句。类似于:
mysql代码
CREATE TABLE `mytable` (
`tableid` bigint(20) unsigned NOT NULL,
`c1` int(10) unsigned NOT NULL default '0',
`c2` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`tableid`)
);
注意看最后的分号,缺少了一点点东西:engine=myisam DEFAULT CHARSET=utf8 engine 和 charset 的意义地球人都知道啊... 将这一段加进去。结果可能是这样:
mysql代码
CREATE TABLE `mytable` (
`tableid` bigint(20) unsigned NOT NULL,
`c1` int(10) unsigned NOT NULL default '0',
`c2` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`tableid`)
) engine=myisam DEFAULT CHARSET=utf8;
其中engine 和 charset 改成期望的东西,如:innodb gbk 等...
保存文件。(如果是用UE等工具即使文件大也不会等太久,如果用记事本打开的……恭喜你!)
这样就成功了一半了,剩下的工作只需要导入这个转好码的数据了。
将原来的那个表改名,一是为了备份,二是防止导入的时候说表已经存在。
然后还是进入mysql/bin 下面,运行:
mysql代码
mysql -u root -p mydb
输入密码以后程序开始工作,一段时间以后,新表就出来咯...
mission complete!

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

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.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

Dreamweaver CS6
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor