MySQL

 

1)MySQL5.7及以上修改数据库默认root账户密码

ALTER USER 'root'@'cdb-oqzyjp2j.gz.tencentcdb.com' IDENTIFIED WITH mysql_native_password BY 'root';

 

mac安装MySQL后,在偏好设置里面启动服务,如果terminal提示mysql不存在,1)sudo vim ~/.bash_profile 2)export PATH=${PATH}:/usr/local/mysql/bin 3)source ~/.bash_profile

Mac安装会提供一个临时密码,首先mysql -uroot -p,然后输入密码登录成功后,执行set password = 'root';

2)导出远程MySQL服务器中的数据库并限制每个表的导出数量

mysqldump -h10.10.21.136 -P3306 -uroot -proot -x shwmm --where="true limit 1000" > C:\shwmm.sql

关于MySQL导出数据库时,mysqldump和Navicat导出的区别,Navicat如果导出一万条数据,会给每条语句生成insert语句,用resouce需要执行一万次,而使用mysqdump导出的数据,只需执行一次批量插入操作(网上的言论)

导入数据的操作:1)连接mysql如 mysql -uroot -proot --default-character-set=utf8  2)执行 source C:\zp\shwmm.sql

备注登录成功之后可以通过 show variables like  "%char%";查询字符集。

 -default-character-set=utf8;参数非常重要,如果你导出的数据字符集是UTF-8,在window命令行下导入会出错,报ERROR: Unknown command '\''错误。

不加参数如图1所示,连接的客户端以及结果集都是gbk编码。

 

3)查询当前连接下所有数据库占用空间大小及表的数量

-- 查询当前连接下所有数据库占用空间大小及表的数量
select table_schema, sum(data_length+index_length)/1024/1024 as total_mb,   
sum(data_length)/1024/1024 as data_mb, sum(index_length)/1024/1024 as index_mb,   
count(*) as tables, curdate() as today from information_schema.tables group by table_schema order by 2 desc;  

4)查询所有表占用空间大小,并根据表行数进行排序(这样可以确定mysqldump时需要导出数据限定的行数)

-- 查询所有表占用空间大小,并根据表行数进行排序(这样可以确定mysqldump时需要导出数据限定的行数)
select table_name, (data_length/1024/1024) as data_mb , (index_length/1024/1024)   
as index_mb, ((data_length+index_length)/1024/1024) as all_mb, table_rows   
from information_schema.tables where table_schema = 'shwmm' ORDER BY table_rows DESC

5)查询单张表的信息

show table status from shwmm where name = 'am_alarm_def' \G

 

 6)仅查询所有表的记录行数,并排序

-- 仅查询所有表的记录行数,并排序
use information_schema; 
select table_name,table_rows from tables 
where TABLE_SCHEMA = 'shwmm'
order by table_rows desc;

7)仅查询所有表占用空间及索引大小

-- 仅查询所有表占用空间及索引大小
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 = 'shwmm'
group by TABLE_NAME 
order by data_length desc;

 

posted on 2018-09-24 23:09  ${}  阅读(492)  评论(0编辑  收藏  举报

导航