mysql 常用命令

2017/3/10 posted in  SQL
set names utf8
source

select语句 into outfile '外部文件路径' fields terminated by '|' enclosed by '"' lines terminated by '\r\n' ;
load data infile '外部文件路径' into table 表名 fields terminated by '|' enclosed by '"' lines terminated by '\r\n' ;

mysqldump -u 用户名 -p 数据库名 > 导出的文件名
mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名

只导出表结构
mysqldump -u 用户名 -p -d --add-drop-table 数据库名 > 导出的文件名

mysqldump  -uroot -p --databases test mysql #空格分隔
mysqldump  -uroot -p -all-databases
mysql -uroot -proot test < test.sql

查看锁等待

SELECT 
    r.trx_id waiting_trx_id,
    r.trx_mysql_thread_id waiting_thread,
    r.trx_query waiting_query,
    b.trx_id blocking_trx_id,
    b.trx_mysql_thread_id blocking_thread,
    b.trx_query blocking_query
FROM
    information_schema.innodb_lock_waits w
        INNER JOIN
    information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
        INNER JOIN
    information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id;