Mysql多版本多实例

1
2
3
4
5
6
7
yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*

# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# su -  
# mkdir ~/src
# cd src
# wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73.tar.gz
# wget http://down1.chinaunix.net/distfiles/mysql-5.0.56.tar.gz

useradd mysql

# mkdir -p /usr/local/mysql{3306,3307}/data
# mkdir -p /usr/local/mysql{3306,3307}/log

# chown -R mysql:mysql /usr/local/mysql{3306,3307}/data/
# chown -R mysql:mysql /usr/local/mysql{3306,3307}/log/
# chmod 750 /usr/local/mysql{3306,3307}/data
# chmod 750 /usr/local/mysql{3306,3307}/log

# mkdir -p /usr/local/mysql{3306,3307}/etc
# chown -R mysql.mysql /usr/local/mysql{3306,3307}/etc
# mkdir -p /var/run/mysqld{3306,3307}
# chown -R mysql.mysql /var/run/mysqld{3306,3307}
# mkdir -p /var/lib/mysqld{3306,3307}
# chown -R mysql.mysql /var/lib/mysqld{3306,3307}
# cp /etc/my.cnf /usr/local/mysql{3306,3307}/etc

# cd ~/src
# tar -zxvf mysql-5.0.56.tar.gz
# cd mysql-5.0.56
./configure --prefix=/usr/local/mysql3306 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3306/etc --localstatedir=/usr/local/mysql3306/data --with-tcp-port=3306 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=utf-8 -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3306.sock
# make
# make install

# cd ~/src
# tar -zxvf mysql-5.1.71.tar.gz
# cd mysql-5.1.71
./configure --prefix=/usr/local/mysql3307 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3307/etc --localstatedir=/usr/local/mysql3307/data --with-tcp-port=3307 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=utf-8 -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3307.sock
# make
# make install


处理my.cnf文件

cp /data/tools/mysql-5.1.73/support-files/my-medium.cnf /usr/local/mysql3306/etc/my.cnf

ln -s /usr/local/mysql3306/lib/mysql /usr/lib/mysql

# cd /usr/local/mysql3306
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3306/data

# cd /usr/local/mysql3307
# scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql3307/data

# cp /usr/local/mysql3306/support-files/mysql.server.sh /etc/init.d/mysqld3306
# cp /usr/local/mysql3307/support-files/mysql.server.sh /etc/init.d/mysqld3307


# vi /etc/init.d/mysqld3006

basedir=/usr/local/mysql3306
datadir=/usr/local/mysql3306/data
conf=/usr/local/mysql3306/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &


# vi /etc/init.d/mysqld3007

basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/data
conf=/usr/local/mysql3307/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &



/etc/init.d/mysqld3306 start

mysql -S/tmp/mysql3306.sock
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
###
MYSQL5.7
yum -y install gcc gcc-c++ ncurses ncurses-devel cmake
wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73.tar.gz
useradd -M -s /sbin/nologin mysql
tar xzf boost_1_59_0.tar.gz
tar xzf mysql-5.7.173.tar.gz
mkdir -p /data/mysql
chown -R mysql.mysql /data/mysql
mv boost_1_59_0 /usr/local/boost
cd mysql-5.7.73

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql3307 \
-DMYSQL_DATADIR=/usr/local/mysql3307/data \
-DMYSQL_TCP_PORT=3307 \
-DMYSQL_UNIX_ADDR=/tmp/mysql3307.sock \
-DSYSCONFDIR=/usr/local/mysql3307/etc \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1
编译安装
make #编译很消耗系统资源,小内存可能编译通不过
make install
编译出错,删除下面文件,重新编译安装。
#rm -f CMakeCache.txt
#make && make install

其他参考上
1
2
3
4
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile    //加入环境变量
source /etc/profile //更新环境变量

删除 /etc/my.cnf (不能有重复的my.cnf)