MySQL杂记(更新时间2014.05.23)_MySQL
-
-- 导出远程数据
mysqldump.exe--defaults-extra-file="c:/docume~1/admini~1/locals~1/temp/tmpx9h0e7.cnf"
--set-gtid-purged=OFF --user=tongzhou --max_allowed_packet=1G
--host=192.168.1.102 --port=3306 --default-character-set=utf8 "datacenterb" "cib_cs_130805_s2014"
(该操作是从mysqlwokbench 工具中远程导出表的时候生成的语句,但是还没有测试过) 数据库试用规约
以下的注意事项主要是为了:提高查询速递、减少数据库的压力
导入导出数据
-
本地导入mysql数据
mysql source D:/123.sql;
本地导出mysql数据
mysqldump -u root -p test >D:/456.sql 导出数据修改密码root
mysqladmin -u 用户名 password 新密码 –p
mysqladmin -u root -p password mypasswd
执行后提示输入旧密码,确认后即修改成功mysql授权语句(database 是数据库的名称,username是用户名密码 root 是用户名)
grant all privileges on datacenterb.* to root@'%' identified by 'username';
刷新权限(一定记得,有些时候他不刷新的话不能很快的反应过来)
flush privileges;批量删除数据库中的表 (没有比这个更简单的语句了,目的是组合删除语句,而后自己执行该删除句子)
select CONCAT( 'drop table ', table_name, ';' ) from information_schema.tables where table_schema='database1' and table_name like'%cache';
mysql批量导入导出
导出
mysqldump -uROOT -pROOT -hlocalhost DB2014 2012_05051_s201401 > D:/outfile/1.sqlmysqldump -uROOT -pROOT -hlocalhost DB2014 2012_05051_s201402 > D:/outfile/2.sqlmysqldump -uROOT -pROOT -hlocalhost DB2014 2012_05051_s201403 > D:/outfile/3.sq
Copy after login导入
mysql -uROOT -pROOT -hlocalhost DBtest < D:/outfile/1.sqlmysql -uROOT -pROOT -hlocalhost DBtest < D:/outfile/2.sqlmysql -uROOT -pROOT -hlocalhost DBtest < D:/outfile/3.sql
Copy after loginPS:这个导出的文件名称以可以随便指定,但是文件的后缀名称必须是sql
Windows netstat 查看端口、进程占用
目标:在Windows环境下,用netstat命令查看某个端口号是否占用,为哪个进程所占用操作:操作分为两步:
(1)查看该端口被那个PID所占用;
方法一:有针对性的查看端口,使用命令Netstat –ano|findstr “”,如图,最后一列为PID。图中的端口号为1068,所对应的PID为3840。 eg ——〉Netstat –ano|findstr "65340"
方法二:查看所有的,然后找到对应的端口和PID。eg ——〉netstat -ano
(2)查看该PID对应的进程名称。
方法一:一直用命令查找,tasklist|findstr “
” 方法二:用任务管理器查看。
附录:在命令行中输入netstat /? 可以查看netstat的相关信息。
-
###
i. 所有和数据库的链接(connection)必须是打开、使用、关闭;
ii. 给经常使用的某一列建立索引和约束(索引是因为实际生产的需要)(约束该项有待商榷);
iii. 写入数据库(insert into table)的时候尽量用批量提交的方式(批量提交分java程序控制——java的批量提交方式,以及程序员手动控制——自己组合insert 语句两种);
iv. 在实际的查询中如果select需要查询所有的列,则用select* 否则尽量使用select+ column 的查询方式;
v. 子查询的使用:不要超过二级子查询,因为数据量大的原因,二级子查询可能导致数据库的超时;
vi. 视图的使用:尽量不要建立二级视图(视图上建立视图),因为二级视图会严重影响查询的效率;
vii. 字段长度:不要太长,但也要给字段留有余地;

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

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



InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.
