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、最大超時時間設置
參考:
https://www.cnblogs.com/ivictor/p/5979731.html
4、鎖表問題
參考:
https://www.iteye.com/blog/johnny-lee-2434634
5、truncate
參考:
https://blog.csdn.net/qq_37871669/article/details/9864754