1. 程式人生 > 實用技巧 >mysql命令

mysql命令

1、linux系統下啟動/停止mysql服務(寫出一種即可)
service mysqld start/mysqld start/safe_mysqld&
service mysqld stop/mysqld stop/mysqladmin shutdown


2、使用SQL檢視testtable表的大小(DATA_LENGTH)。小提示:information_schema.TABLES
SELECTDATA_LENGTHFROM information_schema.TABLES WHERETABLE_NAME='testtable';


3、使用SQL建立使用者testuser,密碼”testuser”,並給testuser賦予testdb所有許可權

create user testuser@'%' identified by testuser;
grant all privileges on testdb.* to testuser @'%' identified by 'testuser';

4、使用SQL檢視testdb的當前總的連線數。小提示:information_schema.PROCESSLIST

select count(1) from information_schema.PROCESSLIST where db = 'testdb';

5、使用SQL檢視設定的慢查詢時間(小提示:long_query_time)

show variables like "long_query_time";

6、使用SQL檢視設定的慢查詢日誌路徑(小提示:slow_query_log_file)
show variables like "slow_query_log_file";


7、使用命令備份資料庫mysql_testdb,備份檔名mysql_testdb.sql
mysqldump -uroot -p mysql_testdb > mysql_testdb.sql


8、已有資料備份檔案/home/mysql_testdb.sql,請使用命令進行資料恢復
mysql -uroot -p test_db < /home/mysql_testdb.sql