1、关闭防火墙
[[email protected] ~]# service iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] [[email protected] ~]# chkconfig iptables off [[email protected] ~]# chkconfig iptables --list iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
2、关闭selinux
[[email protected] ~]# setenforce 0 [[email protected] ~]# vim /etc/sysconfig/selinux
修改下面这一行;
SELINUX=disabled
[[email protected] ~]# getenforce Permissive
3、安装mysql依赖包及编译工具;
[[email protected] ~]# yum install libaio-devel -y [[email protected] ~]# yum install -y ncurses-devel [[email protected] ~]# yum install -y gcc gcc-c++ [[email protected] ~]# yum install -y cmake
4、安装前准备;
4.1、安装路径:
[[email protected] ~]# mkdir /usr/local/mysql
4.2、数据库路径:
[[email protected] ~]# mkdir /data/mysql -p
4.3、创建用户和用户组
[[email protected] ~]# groupadd mysql [[email protected] ~]# useradd -r -g mysql -s /bin/false mysql
4.4、赋予数据存放目录权限
[[email protected] ~]# chown mysql:mysql -R /data/mysql
5、编译安装mysql 5.5.35
[[email protected] ~]# yum install -y lrzsz [email protected] ~]# mkdir /package [[email protected] ~]# cd /package/ [[email protected] package]# tar xf mysql-5.5.32.tar.gz [[email protected] package]# cd mysql-5.5.32 [[email protected] mysql-5.5.32]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/ -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 [[email protected] mysql-5.5.32]# make && make install
6、创建多实例数据库文件存放位置;
[[email protected] ~]# mkdir -p /data/{3306,3307}/data [[email protected] ~]# tree /data /data |-- 3306 | `-- data `-- 3307 `-- data 4 directories, 0 files
7、修改配置文件(my.cnf)如下行,分别放入3306、3307目录当中;
[[email protected] 3306]# vim my.cnf [client] port = 3306 socket = /data/3306/mysql.sock [mysqld] port = 3306 socket = /data/3306/mysql.sock datadir = /data/3306 server-id = 3306
8、初始化数据库;
注意:初始化数据库时需要指定不同的数据目录
[[email protected] mysql-5.5.32]# cd /usr/local/mysql/ [[email protected] mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306 [[email protected] mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307
9、启动多实例,启动脚本可以加入到开机自启动文件中。
[[email protected] mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf 2>&1 >/dev/null & [[email protected] mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf 2>&1 >/dev/null &
9.1、查看端口;
[[email protected] mysql]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 11621/mysqld tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1266/sshd tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11338/mysqld tcp 0 0 :::22 :::* LISTEN 1266/sshd udp 0 0 0.0.0.0:68 0.0.0.0:* 969/dhclient
10、登录多实例数据库
[[email protected] mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3306 -S /data/3306/mysql.sock [[email protected] mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3307 -S /data/3307/mysql.sock
11、关闭mysql多实例方式
[[email protected] mysql]# /usr/local/mysql/bin/mysqladmin -u root -p -P 3306 -S /data/3306/mysql.sock shutdown [[email protected] mysql]# /usr/local/mysql/bin/mysqladmin -u root -p -P 3307 -S /data/3307/mysql.sock shutdown
时间: 2024-12-27 21:07:36