日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql使用释放资源_数据库--释放mysql数据库资源

發(fā)布時間:2025/4/5 数据库 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql使用释放资源_数据库--释放mysql数据库资源 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

數(shù)據(jù)庫--釋放mysql數(shù)據(jù)庫資源

背景

nikeodong 之前做了項目的數(shù)據(jù)庫主從,在全備的過程發(fā)現(xiàn)數(shù)據(jù)庫是越來越大了;最后發(fā)現(xiàn)是資源不釋放的問題。

目的

為了解決 mysql 資源不釋放的問題。

步驟

1、vim /etc/my.cnf,關(guān)閉 log_bin 日志。

2、導(dǎo)出數(shù)據(jù)庫 sql:time mysqldump -q -uroot -p'dpENoKNhG#y0w4sK' --max_allowed_packet=128M --net_buffer_length=16M -e --all-databases > XXXX.sql

3、刪除 mysql 的 data 日志

通過命令:show variables like'datadir',找到data目錄

或者通過vim/etc/my.cnf-->找到里面的datadir的值,找到data目錄

4、重新導(dǎo)入表空間:mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql --default-storage-engine=INNODB&

5、重新開啟 lob_bin 日志

注意:在執(zhí)行第二步的時候可能會報錯

報錯:Error: Table "mysql"."innodb_index_stats" not found。如下是解決方法

顯示有幾個系統(tǒng)表不存在.

innodb_table_stats

innodb_index_stats

或者

slave_master_info

slave_relay_log_info

slave_worker_info

這是因為數(shù)據(jù)庫初始化的時候,dba可能刪除過ibdata1文件

雖然重啟之后,數(shù)據(jù)庫會自動創(chuàng)建一個ibdata1文件,因為是innodb引擎,所以不能訪問了.

解決的方法如下:

刪除上述系統(tǒng)表

drop table mysql.innodb_index_stats;

drop table mysql.innodb_table_stats;

drop table mysql.slave_master_info;

drop table mysql.slave_relay_log_info;

drop table mysql.slave_worker_info;

刪除相關(guān)的.frm.ibd文件

rm-rf innodb_index_stats*

rm-rf innodb_table_stats*

rm-rf slave_master_info*

rm-rf slave_relay_log_info*

rm-rf slave_worker_info*

重新創(chuàng)建上述系統(tǒng)表

CREATE TABLE`innodb_index_stats`(

`database_name`varchar(64)COLLATE utf8_bin NOT NULL,

`table_name`varchar(64)COLLATE utf8_bin NOT NULL,

`index_name`varchar(64)COLLATE utf8_bin NOT NULL,

`last_update`timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

`stat_name`varchar(64)COLLATE utf8_bin NOT NULL,

`stat_value`bigint(20)unsignedNOT NULL,

`sample_size`bigint(20)unsignedDEFAULT NULL,

`stat_description`varchar(1024)COLLATE utf8_bin NOT NULL,

PRIMARY KEY(`database_name`,`table_name`,`index_name`,`stat_name`)

)ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;

CREATE TABLE`innodb_table_stats`(

`database_name`varchar(64)COLLATE utf8_bin NOT NULL,

`table_name`varchar(64)COLLATE utf8_bin NOT NULL,

`last_update`timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

`n_rows`bigint(20)unsignedNOT NULL,

`clustered_index_size`bigint(20)unsignedNOT NULL,

`sum_of_other_index_sizes`bigint(20)unsignedNOT NULL,

PRIMARY KEY(`database_name`,`table_name`)

)ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;

CREATE TABLE`slave_master_info`(

`Number_of_lines`int(10)unsignedNOT NULL COMMENT'Number of lines in the file.',

`Master_log_name`text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT'The name of the master binary log currently being read from the master.',

`Master_log_pos`bigint(20)unsignedNOT NULL COMMENT'The master log position of the last read event.',

`Host`char(64)CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT''COMMENT'The host name of the master.',

`User_name`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The user name used to connect to the master.',

`User_password`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The password used to connect to the master.',

`Port`int(10)unsignedNOT NULL COMMENT'The network port used to connect to the master.',

`Connect_retry`int(10)unsignedNOT NULL COMMENT'The period (in seconds) that the slave will wait before trying to reconnect to the master.',

`Enabled_ssl`tinyint(1)NOT NULL COMMENT'Indicates whether the server supports SSL connections.',

`Ssl_ca`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The file used for the Certificate Authority (CA) certificate.',

`Ssl_capath`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The path to the Certificate Authority (CA) certificates.',

`Ssl_cert`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The name of the SSL certificate file.',

`Ssl_cipher`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The name of the cipher in use for the SSL connection.',

`Ssl_key`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The name of the SSL key file.',

`Ssl_verify_server_cert`tinyint(1)NOT NULL COMMENT'Whether to verify the server certificate.',

`Heartbeat`floatNOT NULL,

`Bind`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'Displays which interface is employed when connecting to the MySQL server',

`Ignored_server_ids`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The number of server IDs to be ignored, followed by the actual server IDs',

`Uuid`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The master server uuid.',

`Retry_count`bigint(20)unsignedNOT NULL COMMENT'Number of reconnect attempts, to the master, before giving up.',

`Ssl_crl`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The file used for the Certificate Revocation List (CRL)',

`Ssl_crlpath`text CHARACTER SET utf8 COLLATE utf8_bin COMMENT'The path used for Certificate Revocation List (CRL) files',

`Enabled_auto_position`tinyint(1)NOT NULL COMMENT'Indicates whether GTIDs will be used to retrieve events from the master.',

PRIMARY KEY(`Host`,`Port`)

)ENGINE=InnoDBDEFAULT CHARSET=utf8 STATS_PERSISTENT=0COMMENT='Master Information';

CREATE TABLE`slave_relay_log_info`(

`Number_of_lines`int(10)unsignedNOT NULL COMMENT'Number of lines in the file or rows in the table. Used to version table definitions.',

`Relay_log_name`text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT'The name of the current relay log file.',

`Relay_log_pos`bigint(20)unsignedNOT NULL COMMENT'The relay log position of the last executed event.',

`Master_log_name`text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT'The name of the master binary log file from which the events in the relay log file were read.',

`Master_log_pos`bigint(20)unsignedNOT NULL COMMENT'The master log position of the last executed event.',

`Sql_delay`int(11)NOT NULL COMMENT'The number of seconds that the slave must lag behind the master.',

`Number_of_workers`int(10)unsignedNOT NULL,

`Id`int(10)unsignedNOT NULL COMMENT'Internal Id that uniquely identifies this record.',

PRIMARY KEY(`Id`)

)ENGINE=InnoDBDEFAULT CHARSET=utf8 STATS_PERSISTENT=0COMMENT='Relay Log Information';

CREATE TABLE`slave_worker_info`(

`Id`int(10)unsignedNOT NULL,

`Relay_log_name`text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,

`Relay_log_pos`bigint(20)unsignedNOT NULL,

`Master_log_name`text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,

`Master_log_pos`bigint(20)unsignedNOT NULL,

`Checkpoint_relay_log_name`text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,

`Checkpoint_relay_log_pos`bigint(20)unsignedNOT NULL,

`Checkpoint_master_log_name`text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,

`Checkpoint_master_log_pos`bigint(20)unsignedNOT NULL,

`Checkpoint_seqno`int(10)unsignedNOT NULL,

`Checkpoint_group_size`int(10)unsignedNOT NULL,

`Checkpoint_group_bitmap`blob NOT NULL,

PRIMARY KEY(`Id`)

)ENGINE=InnoDBDEFAULT CHARSET=utf8 STATS_PERSISTENT=0COMMENT='Worker Information';

在執(zhí)行刪除表的時候報錯也沒關(guān)系,一直從頭走到尾就好。

完成之后查看一下大小

du -sh /var/lib/mysql 看看數(shù)據(jù)庫是否瘦身成功

來源: http://www.cnblogs.com/nikeodong/p/7137211.html

總結(jié)

以上是生活随笔為你收集整理的mysql使用释放资源_数据库--释放mysql数据库资源的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。