1.加索引
ALTER TABLE `table_name` ADD INDEX index_name ( `column` )
2.重命名表
RENAME TABLE user11 TO user10;
3.用命令导出带条件的sql语句
一般来讲,我们用mysqldump命令,都是用来备份整张表,或整个db的,其实mysqldump还有一个参数,就是--where 指定条件,这样我们就可以对一张表里的某些符合条件的数据,进行备份,导出.sql文件了
cd /usr/local/mysql/bin
./mysqldump -u root -p diot --no-create-db=TRUE --no-create-info=TRUE --add-drop-table=FALSE --where=" data_time >= '2019-07-01 00:00:00' and data_time <='2019-07-01 23:59:59' " smp_equip_realtimedata >myexport.sql;
模板:
mysqldump -u root -p DB_Name --no-create-db=TRUE --no-create-info=TRUE --add-drop-table=FALSE -- where="id>1000" Table_Name >导出文件名.sql;
4.NOT EXISTS
以下语句为找出在smp_equipment 中有,在smp_equipment_small中没有的数据,两个表的主键为id.
select a.* from smp_equipment a where NOT EXISTS(select * from smp_equipment_small b where b.id=a.id)
5.创建用户
--创建了一个名为:test 密码为:1234 的用户
create user 'test'@'localhost' identified by '1234';
赋权限
--授予用户test通过外网IP对数据库“testdb”的全部权限
grant all privileges on 'testdb'.* to 'test'@'%' identified by '1234';
--刷新权限
flush privileges;
--授予用户“test”通过外网IP对于该数据库“testdb”中表的创建、修改、删除权限,以及表数据的增删查改权限
grant create,alter,drop,select,insert,update,delete on testdb.* to test@'%';
2.查询用户
--查询用户
select user,host from mysql.user;
3.删除用户
--删除用户“test”
drop user test@localhost ;
--若创建的用户允许任何电脑登陆,删除用户如下
drop user test@'%';
4.更改密码
--方法1,密码实时更新;修改用户“test”的密码为“1122”
set password for test =password('1122');
--方法2,需要刷新;修改用户“test”的密码为“1234”
update mysql.user set password=password('1234') where user='test'
--刷新
flush privileges;
6.查看用户权限
--查看用户“test”
show grants for test;
7.给已经建好的表加上唯一性约束
ALTER TABLE `t_user` ADD unique(`username`);
8. The total number of locks exceeds the lock table size"的解决方法
InnoDB表执行大批量数据的更新,插入,删除操作时会出现这个问题,需要调整InnoDB全局的innodb_buffer_pool_size的值来解决这个问题,并且重启mysql服务。
show variables like "%_buffer%";
如图,我已设置为3G,
设置方法:找到mysql的配置文件my.cnf,添加一行 innodb_buffer_pool_size=3000M

9. 查看mysql 表的大小
select concat(round(sum(DATA_LENGTH/1024/1024/1024),2),'G') from information_schema.tables;

本文介绍了MySQL数据库中的实用操作技巧,包括添加索引、重命名表、导出特定条件数据、使用NOT EXISTS查询、用户管理、增加唯一性约束等。同时提供了调整InnoDB锁表大小的方法及查看表大小的SQL语句。
2597

被折叠的 条评论
为什么被折叠?



