为了账号安全,请及时绑定邮箱和手机立即绑定

centos编译安装mysql 5.6及安装多个mysql实例详解

标签:
MySQL

--1.为mysql新建组和用户

?

1# useradd -M -s /sbin/nologin mysql

--2.安装需要的库,编译器

?

1# yum install ncurses-devel openssl-devel cmake -y

--3.解压

?

12# tar zxvf mysql-5.6.35.tar.gz# cd mysql-5.6.35

--4.编译安装

?


# cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/usr/local/mysql/data \-DSYSCONFDIR=/etc \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DMYSQL_USER=mysql \-DWITH_DEBUG=0 \-DWITH_SSL=system# make# make install

--5.拷贝模版,作为配置文件

?

1# cp support-files/my-default.cnf /etc/my.cnf

--6.设置mysql权限

?

1# chown -R mysql.mysql /usr/local/mysql/

--7.初始化mysql数据库

?

123# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql# chown -R root /usr/local/mysql/# chown -R mysql /usr/local/mysql/data/


--8.设置mysql开机自启动


?

123# cp support-files/mysql.server /etc/init.d/mysqld# chmod +x /etc/init.d/mysqld# chkconfig mysqld on

--9.测试并运行mysql

?

1#service mysqld start

--10.修改mysql管理员密码

?

1#/usr/local/mysql/bin/mysqladmin -u root password '要设置的密码'

--11.使用用户登录mysql

?

1# /usr/local/mysql/bin/mysql -u root -p

--12.加入环境变量

?

12# echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profile# source /etc/profile

            CentOS 6.5最小化编译安装mysql 5.5.35配置多实例

1、关闭防火墙

?


1234567 [root@mysql ~]# service iptables stopiptables: Setting chains to policy ACCEPT: filter   [ OK ]iptables: Flushing firewall rules:       [ OK ]iptables: Unloading modules:        [ OK ][root@mysql ~]# chkconfig iptables off[root@mysql ~]# chkconfig iptables --listiptables  0:off 1:off 2:off 3:off 4:off 5:off 6:off

2、关闭selinux

?

1212 [root@mysql ~]# setenforce 0[root@mysql ~]# vim /etc/sysconfig/selinux

修改下面这一行;

?

123SELINUX=disabled12 [root@mysql ~]# getenforce Permissive

3、安装mysql依赖包及编译工具;

?

12341234 [root@mysql ~]# yum install libaio-devel -y[root@mysql ~]# yum install -y ncurses-devel[root@mysql ~]# yum install -y gcc gcc-c++ [root@mysql ~]# yum install -y cmake

4、安装前准备;

4.1、安装路径:

?

11 [root@mysql ~]# mkdir /usr/local/mysql

4.2、数据库路径:

?

11 [root@mysql ~]# mkdir /data/mysql -p

4.3、创建用户和用户组

?

1212 [root@mysql ~]# groupadd mysql[root@mysql ~]# useradd -r -g mysql -s /bin/false mysql

4.4、赋予数据存放目录权限

?

11 [root@mysql ~]# chown mysql:mysql -R /data/mysql


5、编译安装mysql 5.5.35

?


1234567 [root@mysql ~]# yum install -y lrzszroot@mysql ~]# mkdir /package[root@mysql ~]# cd /package/[root@mysql package]# tar xf mysql-5.5.32.tar.gz [root@mysql package]# cd mysql-5.5.32[root@mysql 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[root@mysql mysql-5.5.32]# make && make install

6、创建多实例数据库文件存放位置;

?

1234567812345678 [root@mysql ~]# mkdir -p /data/{3306,3307}/data[root@mysql ~]# tree /data/data|-- 3306|  `-- data`-- 3307  `-- data4 directories, 0 files

7、修改配置文件(my.cnf)如下行,分别放入3306、3307目录当中;

?


123456789 [root@mysql 3306]# vim my.cnf [client]port      = 3306socket     = /data/3306/mysql.sock[mysqld]port      = 3306socket     = /data/3306/mysql.sockdatadir     = /data/3306server-id    = 3306

8、初始化数据库;

注意:初始化数据库时需要指定不同的数据目录

?

123123 [root@mysql mysql-5.5.32]# cd /usr/local/mysql/[root@mysql mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306[root@mysql mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307

9、启动多实例,启动脚本可以加入到开机自启动文件中。

?

1212 [root@mysql mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf 2>&1 >/dev/null &  [root@mysql mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf 2>&1 >/dev/null &

9.1、查看端口;

?


12345678 [root@mysql mysql]# netstat -tunlpActive 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、登录多实例数据库

?

1212 [root@mysql mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3306 -S /data/3306/mysql.sock[root@mysql mysql]# /usr/local/mysql/bin/mysql -u root -p -P 3307 -S /data/3307/mysql.sock

11、关闭mysql多实例方式

?


12 [root@mysql mysql]# /usr/local/mysql/bin/mysqladmin -u root -p -P 3306 -S /data/3306/mysql.sock shutdown  [root@mysql mysql]# /usr/local/mysql/bin/mysqladmin -u root -p -P 3307 -S /data/3307/mysql.sock shutdowncat /etc/my.cnf [mysqld1]datadir=/data/mysqlsocket=/tmp/mysql.sockuser=mysqlsymbolic-links=0skip-name-resolveserver-id=1221max_connections = 2000binlog-ignore-db=mysqlbinlog-ignore-db=testbinlog-ignore-db=information_schemabinlog-ignore-db=performance_schemainnodb_buffer_pool_size = 2Ginnodb_additional_mem_pool=16Minnodb_log_file_size=256Minnodb_flush_log_at_trx_commit=2character_set_server=utf8collation_server = utf8_general_cireplicate_ignore_db = mysqlslave-skip-errors=allrelay_log=/data/mysql/[mysqld2]port=3307server-id=1222log-error=/tmp/mysqld2.logdatadir=/data/mysql_livesocket=/tmp/mysql2.sockuser=mysqlsymbolic-links=0skip-name-resolvecharacter_set_server=utf8collation_server = utf8_general_cimax-connections=500default-storage-engine=INNODBinnodb_file_per_tablelog-bin=mysql-binrelay-log-info-repository=TABLEmaster-info-repository=TABLEexpire_logs_days=10binlog_format=ROWtransaction-isolation=READ-COMMITTEDbinlog-ignore-db=mysqlbinlog-ignore-db=testbinlog-ignore-db=information_schemabinlog-ignore-db=performance_schemaslow_query_log=TRUEslow_query_log_file=/tmp/mysqld_slow_query2.loglong_query_time=3replicate_ignore_db = mysqlslave-skip-errors=all[mysqld3]server-id=1223port=3308log-error=/tmp/mysqld3.logdatadir=/data/mysqlsocket=/tmp/mysql3.sockuser=mysqlsymbolic-links=0skip-name-resolvecharacter_set_server=utf8collation_server = utf8_general_cimax-connections=500default-storage-engine=INNODBinnodb_file_per_tablelog-bin=mysql-binrelay-log-info-repository=TABLEmaster-info-repository=TABLEexpire_logs_days=10binlog_format=ROWtransaction-isolation=READ-COMMITTEDbinlog-ignore-db=mysqlbinlog-ignore-db=testbinlog-ignore-db=information_schemabinlog-ignore-db=performance_schemaslow_query_log=TRUEslow_query_log_file=/tmp/mysqld_slow_query3.loglong_query_time=3replicate_ignore_db = mysqlslave-skip-errors=all[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/data/mysql/mysqld.pid


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消