Home > Database > Mysql Tutorial > 最近整理的mysql常用命令_MySQL

最近整理的mysql常用命令_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:34:47
Original
904 people have browsed it

bitsCN.com

最近整理的mysql常用命令

 

---查看主库log-bin文件号和pos号

mysql -uroot -pzqgame.com -e "show master status/G"|cut -d: -f 2|sed -n '2,3p'

 

---查看表信息

show table status/G;

 

---mysql 记录运行慢sql:

log = /tmp/mysqld.sql

log-slow-queries=/data/mysql/slowquery.log

long_query_time=2

 

---查看建表语句

show create table tablename;

 

---查看表结构

DESCRIBE table_name;

 

---可以查看完整的执行sql

show full processlist;

 

---显示系统中正在运行的所有进程。

show processlist

 

---看系统的资源

show status

 

---看变量,在my.cnf配置文件里定义的

show variables

 

---查看最近一个sql语句产生的错误警告,看其他的需要看.err日志

show warnings

 

---查看错误

show errors

 

---查看负载

/s;

 

--重置mysql密码

service mysql stop 

mysqld_safe –skip-grant-table& 

mysql 

use mysql; 

update user set password = password(‘test’) where user = ‘root’;

 

---更改表的字符集

ALTER TABLE table_name CONVERT TO CHARACTER SET gbk/utf8;

show variables like "%char%";

SET character_set_client='gbk';

SET character_set_connection='gbk';

SET character_set_results='gbk';

 

---查询所有数据的大小 

select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB') as data from information_schema.TABLES;

 

---查看指定数据库实例的大小,比如说数据库 forexpert 

select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB') as data from information_schema.TABLES where table_schema='forexpert';

 

---查看指定数据库的表的大小,比如说数据库 forexpert 中的 member 表 

select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from information_schema.TABLES where table_schema='forexpert' and table_name='member';

 

---查看版本号

select verison();

 

---查看执行计划

explain select ...

 

---索引失效修复

ANALYZE TABLE table_name; 

SHOW INDEX FROM table_name;

 

---修复表

repair table table_name;

 

---清除mysql-bin开头的日志文件

PURGE MASTER LOGS TO 'mysql-bin.010';

PURGE MASTER LOGS BEFORE '2008-12-19 21:00:00';

 

注:如果从服务器已经完全和主服务器同步了,可用RESET MASTER将这些文件删除

 

----分区表相关

查询分区名:

select 

  partition_name part,  

  partition_expression expr,  

  partition_description descr,  

  table_rows  

from information_schema.partitions  where 

  table_schema = schema()  

  and table_name='test'; 

ALTER TABLE emp CHECK partition p1,p2;

这个命令可以告诉你表emp的分区p1,p2中的数据或索引是否已经被破坏。如果发生了这种情况,使用“ALTER TABLE ... REPAIR PARTITION”来修补该分区。

 

----修复主备不一致

 pt-table-sync –execute –sync-to-master h=10.232.31.109 –databases test -uroot -p1234546

 

----mysql卸载

删除rpm包

rpm -qa|grep -i mysql

rpm -e ...

 

删除配置文件(或者重命名)

rm /etc/my.cnf 

 

删除datadir目录

rm /data/mysql

 

删除mysql服务 

rm /etc/init.d/mysql

chkconfig --del mysql

 

删除分散mysql文件夹

whereis mysql

 

分别删除

rm -rf /usr/lib/mysql/  

rm -rf /usr/share/mysql

 

 以上命令为最近整理出来的常用命令,后期还会继续完善。

bitsCN.com
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template