mysql常见用法

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值