Mysql知識記錄

Mysql5.7 yum安裝

下載rpm包
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
安裝rpm包
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum安裝
yum install mysql-server
service mysql start
grep "password" /var/log/mysqld.log 
alter user 'root'@'localhost' identified by '***';
update mysql.user set host='%' where host='localhost';
grant all on *.* to root@'%' identified by '***';
flush privileges;

批量導入數據

load data infile '/data/import200.txt' into table password fields terminated by ':' lines terminated by '\n' (password, sha);

跳過指定行數,場景:批量導入報錯,再次導入跳過之前入庫的數據

load data infile '/data/import200.txt' into table password fields terminated by ':' lines terminated by '\n' ignore 100 lines  (password, sha);

忽略錯誤

load data infile '/data/import200.txt' ignore into table password fields terminated by ':' lines terminated by '\n' (password, sha);

加快批量導入數據的速度

導入前ALTER TABLE...DISABLE KEYS

導入後ALTER TABLE...ENABLE KEYS

創建索引

CREATE INDEX part_of_sha1 ON password (sha1(10));

修改innodb配置,提高導入數據性能

innodb_flush_log_at_trx_commit=0或2
innodb_autoextend_increment=128
innodb_log_buffer_size=16
innodb_log_file_size=128

查看數據大小

select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='alltext' and table_name='password';

SELECT TABLE_NAME,DATA_LENGTH+INDEX_LENGTH,TABLE_ROWS,concat(round((DATA_LENGTH+INDEX_LENGTH)/1024/1024,2), 'MB') as data FROM TABLES WHERE TABLE_SCHEMA='alltext';

在一個耗時的查詢語句中增加超時設置

select /*+ max_execution_time(1000)*/ * from tablea where email like "%dd_ii.com"

SET STATEMENT max_execution_time=1000 for SELECT * FROM `tablea` WHERE `email` LIKE '%@bb-ii.com' ORDER BY `id` LIMIT 20

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章