mysql常見用法

2022-08-17 21:18:12 字數 2168 閱讀 4359

1、常見命令

1.1、檢視所有賬戶資訊

select host,user from mysql.user;

select distinct concat('user: ''',user,'''@''',host,''';') as query from mysql.user;

1.2、修改賬戶密碼

use mysql;

update user set authentication_string=password('root123!') where user='root';

1.3、建立賬戶

create user 'deployusr'@'localhost' identified by 'deploy123!';

create user 'deployusr'@'%' identified by 'deploy123!';

1.4、給庫賦予許可權

use deploy;

grant all privileges on deploy to 'deployusr'@'localhost';

grant select,insert,update,delete,create,drop on deploy.* to 'deployusr'@'localhost';

grant all privileges on deploy.* to 'deployusr'@'%';

1.5、對錶賦予許可權

grant select,insert,update,delete,create,drop on deploy.table1 to 'deployusr'@'%';

1.6、普通使用者想要匯出資料庫中的表需要賦予file許可權

首先賦予其他許可權

grant select,insert,update,delete,create,drop on deploy.* to 'deployusr'@'%';

然後賦予file許可權

grant file on *.* to deployusr@'%';

flush privileges;

預設只能匯出到/var/lib/mysql-files目錄,匯入其他目錄會報錯

1.7、檢視使用者許可權

show grants for deployusr;

show grants for 'deployusr'@'%';

1.8、撤銷許可權

revoke all on deploy from 'deployusr'@'localhost';

flush privileges;

1.9、刪除使用者和庫

delete from user where user='deployusr' and host='localhost';

或者drop user 'deployusr'@'localhost';

flush privileges;

drop database deploy;

1.10、備份資料庫

mysqldump -u root -h host -p deploy > backup_deploy.sql

1.11、備份表

mysqldump -u root -h host -p deploy table1, table2 > backup_deploy_table.sql

1.12、

批量執行插入等操作

把命令寫入.sql的檔案中

登入資料庫

進入相應表

source .sql

1.13、檢視表空間

select table_name, concat(truncate(data_length/1024/1024,2),'mb') as data_size,

concat(truncate(index_length/1024/1024,2),'mb') as index_size

from information_schema.tables where table_schema = 'missing_cust'

group by table_name

order by data_length desc;

2、跳過密碼登入

vi /etc/my.cnf

skip-grant-tables

3、最大超時時間設定

參考:4、鎖表問題

參考:5、truncate

參考:

mysql 常見用法 mysql常見用法

檢視慢日誌 show variables like slow query log show variables like long query time 設定慢日誌記錄什麼樣的sql,預設10s log queries not using indexes 未使用索引的查詢也被記錄到慢查詢日誌中,一般...

Mysql中Regexp常見用法

原文 查詢content欄位中包含 車友俱樂部 的記錄 select from club content where content regexp 車友俱樂部 此時的regexp與like的以下用法是等同的 select from club content where content like 車友...

原創 mysql 常見匯入匯出用法

mysql匯出 1.匯出資料庫 db 結構 mysqldump u root p d db name db name create.sql 2.匯出資料庫 db 含所有資料 mysqldump u root p db name db name data.sql 說明 u 使用者名稱 p 密碼 密碼不...