bitsCN.com
本文章介绍了都是mysql常用的命令一些数据导入导出的命令了,只要我们撑握这些命令就可以方法快速的给我们的数据库进行备份还原了
mysql数据到导入导出 500MB数据
问题:500M的库表数据,需要导入到新的数据库中。
首先通过控制台进入mysql
mysql -u root -p 12345
CREATE DATABASE `demo` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
use demo;切换数据库
source file.sql 导入数据,这其中file.sql在 mysql的bin目录下,也可以修改成自己的路径
问题:导入后出现中文乱码。。。。
重新再来
drop database demo
C utf8;//切换编码
use demo ;
source file.sql;
--------------------------------------------
mysqldump 数据库名 -u root -p -h IP地址 > file.sql
其它关于mysql数据导出导入数据库
导出
mysqldump方法
mysqldump -u用户名 -p密码名 database [table]> 目标文件
导入
mysql -uroot -proot
use database
source 目标文件;
PS: 这种方法是导出整个表数据,并且带着建表信息,假如导入的数据库有同名的表,会被替换
PS: 可以添加条件
mysql -uroot -proot [-n] [-t] [-d] database [table]>name
-t 不包含创建表的信息
-d不包含数据信息
--w or -w筛选条件
1 例:先进入dos cmd命令模式 Ctrl旁边的键+R
2 导出 mysqldump -uroot -proot test student -t -w studentno=10101 >stu
3 导入 mysql -uroot -proot
4 mysql>use test
5 mysql>source stu
方法二
into outfile
load data infile
例子
导出
mysql -uroot -proot
mysql>use test
mysql>select * from student where studentno=10101 into outfile './stu';
导入
mysql -uroot -proot
mysql>use test
mysql>load data infile './stu' into table student;
导出xml
mysqldump --xml -uroot -proot [database] [table]> name.xml
[test]
mysqldump --xml -uroot -proot test>a.xml
mysqldump --xml -uroot -proot test dept>a.xml
mysql -X -uroot -proot -e "use test;select * from dept">a.xml[方法2]
导入xml文件内容到数据库
mysql> create table xmlt(
-> id int ,
-> doc blob
-> );
mysql> insert into xmlt values(1,load_file('/home/a.xml') );
mysql> select * from xmlt;
MYSQL常用命令
1.导出整个数据库
mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1)
mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql
2.导出一个表
mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名
mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql
3.导出一个数据库结构
mysqldump -u wcnc -p -d

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

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

Dreamweaver Mac version
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.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.