MySQL安装+多实例

yum 安装 :    yum  install   mysql-server

编译安装   5.0-5.1

二进制免编译安装

cmake方式编译   5.5-5.6

 1.3 安装相关包

1.3.1 cmake软件

cd /home/oldboy/tools/

tar xf cmake-2.8.8.tar.gz

cd cmake-2.8.8

./configure

#CMake has bootstrapped.  Now run gmake.

gmake

gmake install

cd ../

1.3.2 依赖包

yum install ncurses-devel -y

1.4 开始安装mysql

1.4.1 创建用户和组

groupadd mysql

useradd mysql -s /sbin/nologin -M -g mysql

1.4.2 解压编译MySQL

tar zxf mysql-5.5.32.tar.gz

cd mysql-5.5.32

cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \

-DMYSQL_DATADIR=/application/mysql-5.5.32/data \

-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \

-DWITH_FAST_MUTEXES=1 \

-DWITH_ZLIB=bundled \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_READLINE=1 \

-DWITH_EMBEDDED_SERVER=1 \

-DWITH_DEBUG=0

#-- Build files have been written to: /home/oldboy/tools/mysql-5.5.32

提示,编译时可配置的选项很多,具体可参考结尾附录或官方文档:

make

#[100%] Built target my_safe_process

make install

ln -s /application/mysql-5.5.32/ /application/mysql

如果上述操作未出现错误,则MySQL5.5.32软件cmake方式的安装就算成功了。

初始化

 cp support-files/my-small.cnf  /etc/my.cnf

echo  'export  PATH=/application/mysql/bin:$PATH' >> /etc/profile

 .     /etc/profile 

chown -R mysql.mysql  /application/mysql/data/

chmod -R 1777 /tmp/

 cd /application/mysql/scripts/

 ./mysql_install_db  --basedir=/application/mysql/ --datadir=/application/mysql/data/  --user=mysql 

 cp support-files/mysql.server  /etc/init.d/mysqld

/etc/init.d/mysqld start

 netstat -lntup | grep 3306

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      24072/mysqld

 /application/mysql//bin/mysqladmin -u root password 'new-password'

mysql多实例

就是一个服务器开启多个不同的服务端口,运行多个进程。共用一套安装程序,可以是一个相同的配置文件,启动程序,数据文件。在逻辑上是独立的。利用剩余的资源。节约服务器资源,资源互相抢占问题。

应用场景

资源紧张型公司   并发访问不是特别大 门户网站应用

多配置文件部署方案                单一配置文件部署方案(mysql_multi)

/data

├── 3306    //实例目录

│   └── data  //数据文件

└── 3307      //实例目录

    └── data     //数据文件

spacer.gif  // 上传上去

/data

├── 3306

│   ├── data

│   └── my.cnf

└── 3307

    ├── data

    └── my.cnf

pkill mysqld

多实例启动文件的启动MySQL服务实质:

mysql_safe   --default-file=/data/3306/my.cnf  2&1 > /dev/null &

mysql_safe   --default-file=/data/3307/my.cnf  2&1 > /dev/null &

停止 平滑关闭

mysqladmin -u   root -p123456   -S /data/3306/mysql.sock  shutdown

mysqladmin -u   root -p123456   -S /data/3307/mysql.sock  shutdown

/data

├── 3306

│   ├── data

│   ├── my.cnf

│   └── mysql

└── 3307

    ├── data

    ├── my.cnf

    └── mysql

chown  -R   mysql.mysql   /data

find  /data/  -type  f  -name  "mysql"   | xargs  chmod +x 

初始化mysql数据库文件:创建基础的数据库文件

cd /application/mysql/scripts/

 ./mysql_install_db  --basedir=/application/mysql  --datadir=/data/3306/data  --user=mysql

 ./mysql_install_db  --basedir=/application/mysql  --datadir=/data/3307/data  --user=mysql

启动

/data/3306/mysql start

/data/3307/mysql start


netstat -lntup | grep 330

tail -l /data/3306/mysql_oldboy3306.err

cd /data/3307

vim mysql          //启动文件

mysql_user="root"

mysql_pwd="123456"

mysql -S /data/3306/mysql.sock       //进入mysql

mysql> system mysql  -S  /data/3306/mysql.sock   // 在mysql里面切换

mysqladmin -u root  -S  /data/3306/mysql.sock    password '123123'

mysqladmin -u root  -S  /data/3306/mysql.sock   -p'123123' password '123456'

find  /data/  -type  f  -name  "mysql"   -exec   chmod 700 {}  \;

find  /data/  -type  f  -name  "mysql"   -exec   chown  root.root {}  \;

pkill mysqld

/data/3306/mysql start

/data/3307/mysql start

 ps -ef | grep mysql

root       6780      1  0 05:05 pts/0    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf

root       6824      1  0 05:05 pts/0    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf

mysql      8186   6780  0 05:05 pts/0    00:00:00 /application/mysql-5.5.32/bin/mysqld --defaults-file=/data/3306/my.cnf --basedir=/application/mysql --datadir=/data/3306/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3306/mysql_oldboy3306.err --open-files-limit=1024 --pid-file=/data/3306/mysqld.pid --socket=/data/3306/mysql.sock --port=3306

mysql      8203   6824  0 05:05 pts/0    00:00:00 /application/mysql-5.5.32/bin/mysqld --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3307/mysql_oldboy3307.err --open-files-limit=1024 --pid-file=/data/3307/mysqld.pid --socket=/data/3307/mysql.sock --port=3307

增加3308

mkdir /data/3308/data/  -p

cp /data/3306/my.cnf   /data/3308/

cp /data/3306/mysql     /data/3308/

chown -R mysql.mysql    /data/3308/

cd /data/3308/

vim my.cnf

server-id = 4

:%s/3306/3308/g

vim  mysql 

 cd /application/mysql/scripts/

[root@localhost scripts]# ./mysql_install_db  --user=mysql --basedir=/application/mysql  --datadir=/data/3308/data/

Installing MySQL system tables...

OK

Filling help tables...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/application/mysql/bin/mysqladmin -u root password 'new-password'

/application/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:

/application/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /application/mysql ; /application/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /application/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /application/mysql/scripts/mysqlbug script!

/data/3308/mysql start

mysqladmin -u root  -S  /data/3308/mysql.sock    password '123456'


你可能感兴趣的:(mysql,二进制,软件)