mysql-查看数据库各数据表的容量(及C# 字符串压缩)

Posted 秋飘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql-查看数据库各数据表的容量(及C# 字符串压缩)相关的知识,希望对你有一定的参考价值。

数据库查看各表大小

SELECT
table_schema AS \'数据库\',
table_name AS \'表名\',
table_rows AS \'记录数\',
TRUNCATE (data_length / 1024 / 1024, 2) AS \'数据容量(MB)\',
TRUNCATE (index_length / 1024 / 1024, 2) AS \'索引容量(MB)\'
FROM
information_schema. TABLES
WHERE
table_schema = \'scmnew\' -- 数据库名字
ORDER BY
table_rows DESC;

  

 

C# 字符串压缩

#region  压缩和解压字符串
        /// <summary>
        /// 将传入字符串以GZip算法压缩后,返回Base64编码字符
        /// </summary>
        /// <param name="rawString">需要压缩的字符串</param>
        /// <returns>压缩后的Base64编码的字符串</returns>
        public static string GZipCompressString(string rawString)
        {
            if (string.IsNullOrEmpty(rawString) || rawString.Length == 0)
            {
                return "";
            }
            else
            {
                byte[] rawData = System.Text.Encoding.UTF8.GetBytes(rawString.ToString());
                byte[] zippedData = Compress(rawData);
                return (string)(Convert.ToBase64String(zippedData));
            }
        }

        /// <summary>
        /// GZip压缩
        /// </summary>
        /// <param name="rawData"></param>
        /// <returns></returns>
        static byte[] Compress(byte[] rawData)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.IO.Compression.GZipStream compressedzipStream = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress, true);
            compressedzipStream.Write(rawData, 0, rawData.Length);
            compressedzipStream.Close();
            return ms.ToArray();
        }

        /// <summary>
        /// 解压Sring 
        /// </summary>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static string GetStringByString(string Value)
        {
            //DataSet ds = new DataSet();
            string CC = GZipDecompressString(Value);
            //System.IO.StringReader Sr = new System.IO.StringReader(CC);
            //ds.ReadXml(Sr);
            return CC;
        }

        /// <summary>
        /// 解压
        /// </summary>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static DataSet GetDatasetByString(string Value)
        {
            DataSet ds = new DataSet();
            string CC = GZipDecompressString(Value);
            System.IO.StringReader Sr = new System.IO.StringReader(CC);
            ds.ReadXml(Sr);
            return ds;
        }


        /// <summary>
        /// 将传入的二进制字符串资料以GZip算法解压缩
        /// </summary>
        /// <param name="zippedString">经GZip压缩后的二进制字符串</param>
        /// <returns>原始未压缩字符串</returns>
        public static string GZipDecompressString(string zippedString)
        {
            if (string.IsNullOrEmpty(zippedString) || zippedString.Length == 0)
            {
                return "";
            }
            else
            {
                byte[] zippedData = Convert.FromBase64String(zippedString.ToString());
                return (string)(System.Text.Encoding.UTF8.GetString(Decompress(zippedData)));
            }
        }

        /// <summary>
        /// ZIP解压
        /// </summary>
        /// <param name="zippedData"></param>
        /// <returns></returns>
        public static byte[] Decompress(byte[] zippedData)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream(zippedData);
            System.IO.Compression.GZipStream compressedzipStream = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress);
            System.IO.MemoryStream outBuffer = new System.IO.MemoryStream();
            byte[] block = new byte[1024];
            while (true)
            {
                int bytesRead = compressedzipStream.Read(block, 0, block.Length);
                if (bytesRead <= 0)
                    break;
                else
                    outBuffer.Write(block, 0, bytesRead);
            }
            compressedzipStream.Close();
            return outBuffer.ToArray();

        }
        #endregion

  

以上是关于mysql-查看数据库各数据表的容量(及C# 字符串压缩)的主要内容,如果未能解决你的问题,请参考以下文章

MySQL查看数据库表容量大小

oracle统计各数据库总记录条数及所占容量

MySQL准入规范及容量评估

(转)修改及查看mysql数据库的字符集

MySQL查看数据库表容量大小

MySQL 查看数据库容量大小