当前位置: 代码迷 >> MySQL >> 6、完全卸载Mysql
  详细解决方案

6、完全卸载Mysql

热度:147   发布时间:2016-05-05 17:10:28.0
Mysql源码方式安装与完全卸载Mysql

1、基础环境介绍

1.1软件环境

操作系统:redhat linux 6.3

Mysql版本:Mysql 5.6.24

1.2磁盘目录规划

序号

目录

用途

1

/opt/mysql/mysql-5.6.24

mysql主程序安装目录

2

/data/mysql/mysql_5624/{data,tmp,logs}

存放数据文件、临时文件、日志文件,5624代表为5.6.24版本号

 

2、linux环境调整优化

2.1 关闭NUMA

编辑/etc/grub.conf文件,在kernel后面增加 numa=offelevator=deadline

2.2 关闭selinux

编辑/etc/selinux/config文件,在最后面增加SELINUX=disabled

2.3 修改unlimit参数

编辑/etc/security/limits.conf文件,增加下面四行信息:

root soft nofile 65535

root hard nofile 65535

 

root soft nproc 7000

root hard nproc 7000

2.4 关闭iptables

#service iptables stop

#/etc/init.d/iptables stop

#chkconfig iptables off

2.5 修改环境变量

#Vi .bash_profile

增加下面内容:

export PATH=/usr/local/mysql/bin:/opt/mysql/mysql-5.6.24/bin:$HOME/bin:$PATH

#source .bash_profile

 

由于修改的内容较多,建议到此步时,重启一次linux,并验证参数等配置是否生效。

3、安装mysql

3.1 创建安装与存放数据文件等文件目录

#mkdir –p /opt/mysql/mysql-5.6.24

#mkdir –p /data/mysql/mysql_5624/{data,tmp,logs}

3.2创建Mysql用户与用户组

# groupadd mysql

# useradd -g mysql -s /sbin/nologin -d/opt/mysql mysql

3.3需要安装mysql的DBD模块包

DBD模块包名为:perl-DBD-MySQL-3.0007-2.el5.x86_64.rpm

#yum install cmake *gcc* libaio libaio-devel automake autoconf bzbison libtool ncurses

#yum install perl-DBD-MySQL

 

关于yum的配置,请参考作者发布在博客中的《oracle_linux_6_64(bit)上安装oracle11gR2数据库环境快速准备神器oracle-rdbms-server-11gR2-preinstall》中的第3章节:“为使用oracle-rdbms-server-11gR2-preinstall而搭建一个本地yum服务器”,博文网址:http://blog.csdn.net/ljunjie82/article/details/37373595

 

3.4 下载源码安装包

下载地址:

http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz

3.5 上传压缩文件至服务器

  将下载到的mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz源码安装文件上传到服务器的/opt/mysql/目录下(方法略)

3.6 解压mysql的安装包

#tar -xzvf /opt/mysql/mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz -C/opt/mysql/mysql-5.6.24/

3.7 剪切解压缩后的文件至规划的安装目录

#cd /opt/mysql/mysql-5.6.24

#mv mysql-5.6.24-linux-glibc2.5-x86_64/* .

#rm –rf mysql-5.6.24-linux-glibc2.5-x86_64

3.8 创建ln软链接

创建软链接的目的:为了在服务器上存有多个mysql版本时,可以使用软链接灵活的指向想要使用的版本,在升级时最为有用。

#ln -s /opt/mysql/mysql-5.6.24  /usr/local/mysql

3.9 更改目录权限

#chown -R mysql:mysql /usr/local/mysql

#chown -R mysql:mysql /data/mysql

#chown -R mysql:mysql /opt/mysql

3.10 查看依赖的lib库是否安全

#ldd /usr/local/mysql/bin/mysqld

 

4、配置my.cnf参数与数据库初始化

4.1 配置my.cnf参数

(1)备份/etc/my.cnf

#mv /etc/my.cnf /etc/my.cnf_backup

(2)创建新的/etc/my.cnf文件

#vi /etc/my.cnf

[client]

port = 3306

socket = /tmp/mysql.sock

 

[mysql]

prompt=[master]>

#pager="less -i -n -S"

tee=/data/mysql/mysql_5624/data/query.log

no-auto-rehash

 

[mysqld_multi]

mysqld = /usr/local/mysql/bin/mysqld_safe

mysqladmin = /usr/local/mysql/bin/mysqladmin

log = /opt/mysql/mysqld_multi.log

 

[mysqld]

#misc

explicit_defaults_for_timestamp = ture

user = mysql

basedir = /usr/local/mysql

datadir = /data/mysql/mysql_5624/data

port = 3306

socket = /tmp/mysql.sock

event_scheduler = 0

 

#timeout

interactive_timeout = 300

wait_timeout = 300

 

#character set

character-set-server = utf8

 

open_files_limit = 65535

max_connections = 100

max_connect_errors = 100000

skip-name-resolve = 1

#logs

log-output=file

slow_query_log = 1

slow_query_log_file = slow.log

log-error = /data/mysql/mysql_5624/data/error.log

log_warnings = 2

pid-file = mysql.pid

long_query_time = 1

#log-slow-admin-statements = 1

#log-queries-not-using-indexes = 1

log-slow-slave-statements = 1

 

#binlog

binlog_format = mixed

server-id = 2003306

log-bin = /data/mysql/mysql_5624/logs/mybinlog

binlog_cache_size = 4M

max_binlog_size = 1G

max_binlog_cache_size = 2G

sync_binlog = 0

expire_logs_days = 10

 

#relay log

skip_slave_start = 1

max_relay_log_size = 1G

relay_log_purge = 1

relay_log_recovery = 1

log_slave_updates

#slave-skip-errors=1032,1053,1062

 

#buffers & cache

table_open_cache = 2048

table_definition_cache = 2048

table_open_cache = 2048

max_heap_table_size = 96M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 256

query_cache_size = 0

query_cache_type = 0

query_cache_limit = 256K

query_cache_min_res_unit = 512

thread_stack = 192K

tmp_table_size = 96M

key_buffer_size = 8M

read_buffer_size = 2M

read_rnd_buffer_size = 16M

bulk_insert_buffer_size = 32M

 

#myisam

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

 

#innodb

innodb_buffer_pool_size = 100M

innodb_buffer_pool_instances = 1

innodb_data_file_path = ibdata1:1G:autoextend

innodb_flush_log_at_trx_commit = 1

innodb_log_buffer_size = 64M

innodb_log_file_size = 256M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 50

innodb_file_per_table = 1

innodb_rollback_on_timeout

innodb_status_file = 1

innodb_io_capacity = 2000

transaction_isolation = READ-COMMITTED

innodb_flush_method = O_DIRECT

 

#端口号为3306的实例特殊配置

[mysqld3306]

port = 3306

#指定本实例相应版本的basedir和datadir

basedir= /usr/local/mysql

datadir = /data/mysql/mysql_5624/data

socket          = /tmp/mysql_5624.sock

#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置

innodb_buffer_pool_size = 100m

transaction_isolation = REPEATABLE-READ

 

######以下为多个版本mysql时的相关备用参数#####

#[mysqldXXXX]

#port=3308

#basedir= /usr/local/mysql

#datadir= /data/mysql/mysql_XXXX/data

#socket= /tmp/mysql_XXXX.sock

#重新配置这几个选项,不与全局配置一样,会直接覆盖上面的全局设置

#innodb_buffer_pool_size = 100m

#innodb_flush_log_at_trx_commit = 2

#sync_binlog = 0

 

4.2 初始化mysql

特别注意:初始化数据库一定要在basedir目录下进行

#cd /usr/local/mysql

#./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf

#./scripts/mysql_install_db --datadir=/data/mysql/mysql_5624/data --defaults-file=/etc/my.cnf

5、启动与关闭mysql

5.1 启动mysql

(1)mysql

#/etc/init.d/mysql start

Starting MySQL... SUCCESS!

(2)验证mysql是否在运行

#ps axu |grep mysqld

root      3329  0.1  0.0 106272  1412 pts/0    S    08:27   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/mysql_5624/data --pid-file=/data/mysql/mysql_5624/data/mysql.pid

mysql     4267  3.6 29.6 1121464 565388 pts/0  Sl   08:27   0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/mysql_5624/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql_5624/data/error.log --open-files-limit=65535 --pid-file=/data/mysql/mysql_5624/data/mysql.pid --socket=/tmp/mysql.sock --port=3306

(3)验证配置的3306端口是否被监听

#netstat -nalp|grep "3306"

tcp        0      0 :::3306           :::*           LISTEN      4267/mysqld

 

5.2 关闭mysql

#mysqladmin -uroot shutdown

6、完全卸载Mysql

(1)查询已经安装了的mysql包

#rpm –qa|grep mysql

(2)使用yum完全卸载

# yum remove mysql mysql-server mysql-libsmysql-connector

(3)手工删除所创建的目录及my.cnf文件

#rm –rf /opt/mysql

#rm –rf /data/mysql

#rm /etc/my.cnf

(4)手工删除所创建的软链接

#cd /usr/local

#rm mysql

 

 

本文作者:黎俊杰(网名:踩点),从事”系统架构、操作系统、存储设备、数据库、中间件、应用程序“六个层面系统性的性能优化工作

欢迎加入 系统性能优化专业群,共同探讨性能优化技术。群号:258187244

  相关解决方案