標籤:mysql常用操作記錄
/usr/local/sbin/apachectl graceful
建立使用者 CREATE USER ‘test‘@‘192.168.1.1‘ IDENTIFIED BY ‘111111‘;
授權 grant all privileges on *.* to test@‘localhost’ identified by ‘111111‘; 本機
grant all privileges on *.* to test@‘%’ identified by ‘111111‘; %允許網路端主機訪問資料庫
刪除使用者名稱 DELETE FROM user WHERE User="jude" and Host="localhost";
mysql> UPDATE user SET Password= PASSWORD(‘111111‘) WHERE user=‘mysql‘;
FLUSH PRIVILEGES;
mysql常用維護命令
show processlist
如果是root帳號,你能看到所有使用者的當前串連,如果是其它普通帳號,只能看到自己佔用的串連
show processlist只能列出前100條;如果想全列出請使用show full processlist
1、show global status;列出MySQL伺服器運行各種狀態值
2、show variables;查詢MySQL伺服器配置資訊語句
3、查看慢查詢
show variables like ‘%slow%‘;
show global status like ‘%slow%‘;
4、最大串連數
show variables like ‘max_connections‘;MySQL伺服器最大串連數
show global status like ‘Max_used_connections‘; 伺服器響應的最大串連數
5、查看錶結構
desc Tablename;
describe Tablename;
show columns from Tablename;
show create table Tablename
show binlog enevts in ‘master-bin0000001‘; 產看binlog日誌執行內容
show global variables like ‘read%‘;
vi /etc/my.conf read-only = ON 設定資料庫子讀模式
master_info real_info
sync-binlog =on 在主伺服器設定使用者事務安全
percona-tools percona-toolkit查看mysql主從同步資訊工具
pt-slave-delay -h
還可以查看系統硬體負載
MySQL監控時常用的的幾個MySQL命令。
status = show status like ‘%%’ [例:show status like ‘Com_select‘]
variables = show variables like ‘%%’ [例:show variables like ‘query_cache_size‘]
1、MySQL查詢次數(status)
Com_select;Com_update;Com_insert;Com_delete;Com_change_db
2、查詢快取空間大小:query_cache_size(variables)
查詢快取最大查詢資料集大小:query_cache_limit(variables);
緩衝中的查詢個數:Qcache_inserts(status);
查詢快取命中率:(Qcache_hits/(Qcache_hits+Qcache_inserts))*100% (status)
3、索引快取命中率
索引緩衝空間大小:key_buffer_size (variables)
索引快取命中率:(Key_reads/Key_read_requests)*100% (status)
4、並發串連數
最大充許串連數:max_connections(variables)
實際最大串連數:max_used_connections(status)
當前串連數:Threads_connected(status)
活躍串連數:Threads_running(status)
緩衝串連數:Threads_cache(status)
5、流量統計(status)
Bytes_received ,Bytes_sent(status)
6、串連次數
每秒串連次數:Connections(status)
每秒實際建立串連次數:Threads_created(status)
7、表鎖定統計
立即釋放的表鎖數:Table_locks_immediate(status)
需要等待的表鎖數:Table_locks_waited(status)
Database Backup指令碼
#!/bin/bash
DATE=`date +%Y%m%d%H%M`
DATABASE=test
BACKUP=/data/backup
PASSWORD="111111"
/usr/local/mysql/bin/mysqldump -umysql -h 127.0.0.1 -p$PASSWORD -R --opt $DATABASE |gzip > ${BACKUP}\/${DATABASE}_${DATE}.sql.gz sleep 3
find $BACKUP -mtime +10 |xargs rm -rf
本文出自 “linux學習中..” 部落格,請務必保留此出處http://haozi4263.blog.51cto.com/2791641/1663668
mysql常用操作