1、准备工作
检查操作系统版本、内核版本、selinux是否关闭、防火墙策略、IP地址、主机名配置、host表配置、yum配置
上传cmake、mysql5.6软件包
具体步骤参考源码安装mysql-单实例配置文档
2、安装cmake软件
2.1 安装编译软件环境
[[email protected] ~]# yum -y install gcc-c++ncurses-devel make perl bison ncurses
2.2 解压软件包
[[email protected] ~]# cd /opt/software/
[[email protected] software]# tar -zxfcmake-3.0.1.tar.gz
2.3 编译安装
[[email protected] cmake-3.0.1]# pwd
/opt/software/cmake-3.0.1
[[email protected] cmake-3.0.1]# ./bootstrap
[[email protected] cmake-3.0.1]# gmake&& make install
2.4 校验安装是否成功
[[email protected] ~]# cmake --version
[[email protected] cmake-3.0.1]# cmake --version
cmake version 3.0.1
3、安装mysql
3.1 创建mysql用户、用户组
[[email protected] cmake-3.0.1]# useradd mysql-s ‘/sbin/nologin‘ -r –M //-r创建系统用户,-M不创建home目录
[[email protected] cmake-3.0.1]# id mysql
uid=498(mysql) gid=498(mysql)groups=498(mysql)
3.2 创建mysql安装目录
[[email protected] ~]# mkdir /usr/local/mysql
3.3 创建mysql数据目录
[[email protected] ~]# mkdir -pv/home/mysql/data{3306,3307}
mkdir: created directory `/home/mysql‘
mkdir: created directory`/home/mysql/data3306‘
mkdir: created directory`/home/mysql/data3307‘
[[email protected] ~]# tree /home/mysql/
/home/mysql/
├── data3306
└── data3307
2 directories, 0 files
[[email protected] ~]#
3.5 编译安装mysql5.6
[[email protected] ~]# cd /opt/software
[[email protected] software]# tar -zxfmysql-5.6.16.tar.gz
[[email protected] software]# cd mysql-5.6.16
[[email protected] mysql-5.6.16]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/home/mysql/ \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk
[[email protected] mysql-5.6.16]# make&& make install
4、配置3306数据库主配置文件
[[email protected] ~]# cd /home/mysql/data3306
[[email protected] data3306]# vim my.cnf
[client]
socket = /home/mysql/data3306/mysqld.sock
port = 3306
[mysqld]
basedir =/usr/local/mysql
datadir =/home/mysql/data3306
socket = /home/mysql/data3306/mysqld.sock
port =3306
server_id =1
user = mysql
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
default_storage_engine = InnoDB
join_buffer_size = 128M
max_allowed_packet= 1M
net_buffer_length= 8K
skip-external-locking
skip-host-cache
skip-name-resolve
# InnoDB
innodb_buffer_pool_size = 128M
innodb_log_file_size = 48M
innodb_file_per_table = 1
innodb_flush_method = O_DIRECT
# MyISAM
key_buffer_size = 48M
character-set-server=utf8
collation-server=utf8_general_ci
# LOG
log_error = /home/mysql/data3306/mysql-error.log
long_query_time = 1
slow-query-log
slow_query_log_file = /home/mysql/data3306/mysql-slow.log
# Others
explicit_defaults_for_timestamp=true
max_connections = 500
open_files_limit = 65535
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
5、配置3307数据库主配置文件
[[email protected] data3306]# cp my.cnf../data3307/
[[email protected] data3306]# sed -i‘s/3306/3307/g‘ ../data3307/my.cnf
[[email protected] data3306]# vim../data3307/my.cnf
server_id =2
[[email protected] data3306]# cat ../data3307/my.cnf
[client]
socket =/home/mysql/data3307/mysqld.sock
port = 3307
[mysqld]
basedir =/usr/local/mysql
datadir =/home/mysql/data3307
socket = /home/mysql/data3307/mysqld.sock
port =3307
server_id =2
user = mysql
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
default_storage_engine = InnoDB
join_buffer_size = 128M
max_allowed_packet= 1M
net_buffer_length= 8K
skip-external-locking
skip-host-cache
skip-name-resolve
# InnoDB
innodb_buffer_pool_size = 128M
innodb_log_file_size = 48M
innodb_file_per_table = 1
innodb_flush_method = O_DIRECT
# MyISAM
key_buffer_size = 48M
character-set-server=utf8
collation-server=utf8_general_ci
# LOG
log_error = /home/mysql/data3307/mysql-error.log
long_query_time = 1
slow-query-log
slow_query_log_file = /home/mysql/data3307/mysql-slow.log
# Others
explicit_defaults_for_timestamp=true
max_connections = 500
open_files_limit = 65535
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[[email protected] data3306]#
6、改变数据目录的属主
[[email protected] ~]# chown -R mysql.mysql/home/mysql/data330{6,7}
[[email protected] ~]# ls -ld /home/mysql/data330{6,7}
drwxr-xr-x 2 mysql mysql 4096 Nov 6 18:54 /home/mysql/data3306
drwxr-xr-x 2 mysql mysql 4096 Nov 6 18:54 /home/mysql/data3307
7、配置环境变量
[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] ~]# echo ‘exportPATH=/usr/local/mysql/bin:$PATH‘ >> /etc/profile
[[email protected] ~]# tail -1 /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[[email protected] ~]# source /etc/profile
[[email protected]~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
8、初始化MYSQL多实例数据库文件
[[email protected] scripts]# pwd
/usr/local/mysql/scripts
[[email protected] scripts]# ./mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data3306 --user=mysql
[[email protected] scripts]# ./mysql_install_db--basedir=/usr/local/mysql --datadir=/home/mysql/data3307 --user=mysql
9、启动MYSQL多实例数据库
[[email protected] ~]# mysqld_safe--defaults-file=/home/mysql/data3306/my.cnf 2>&1 > /dev/null &
[[email protected] ~]# mysqld_safe --defaults-file=/home/mysql/data3307/my.cnf2>&1 > /dev/null &
10、设置密码登录
[[email protected] ~]# mysqladmin -S/home/mysql/data3306/mysqld.sock -uroot password ‘123456‘
[[email protected] ~]# mysqladmin -S/home/mysql/data3307/mysqld.sock -uroot password ‘123456‘
11、登录实例,并删除test库及空密码账户
[[email protected] ~]# mysql -S /home/mysql/data3306/mysqld.sock -uroot -p
Enter password:
mysql> status;
mysql> show databases;
mysql> drop database test;
mysql> use mysql;
mysql> select user,host,password fromuser;
mysql> delete from user where password=‘‘;
mysql> flush privileges;
12、停库
[[email protected] ~]# mysqladmin shutdown -S/home/mysql/data3306/mysqld.sock -u root -p
Enter password:
[[email protected] ~]# mysqladmin shutdown -S/home/mysql/data3307/mysqld.sock -u root -p
Enter password:
[[email protected] ~]# ps -ef|grep mysqld|grep-v grep
[[email protected] ~]# netstat -tunlp|grep 330