您的位置:首页 > 运维架构 > Linux

centOS6.6 源码安装mysql-5.7.19多实例

2017-09-20 15:22 441 查看
首先去官网下载mysql-5.7.19.tar.gz和mysql-boost-5.7.19.tar.gz

如图


将文件上传到linux服务器

说明:这里有两个源码包,自5.7版本之后就需要boost这个源码包,文章中所涉及的文件夹目录请根据自己的需要创建或修改

1.解压文件

[root@xin mysql]# tar  -zxf mysql-boost-5.7.19.tar.gz

[root@xin mysql]# tar  -zxf mysql-5.7.19.tar.gz

解压完成后当前目录下会出现 mysql-5.7-19文件夹

2.安装编译源码所需要的包和依赖

[root@xin mysql]# yum install -y cmake make gcc gcc-c++ ncurses-devel

3.安装完成之后执行编译命令

[root@xin mysql-5.7.19]# cmake -DCMAKE_INSTALL_PREFIX=/usr/mysql -DMYSQL_DATADIR=/usr/mysql/mysql_data/ -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/mysql/mysql-5.7.19/boost/boost_1_59_0

可根据需要,修改或新增参数

4.执行编译安装命令

[root@xin mysql-5.7.19]# make && make install

此命令执行时间较长,请耐心等待(若对mysql没有什么特殊的配置要求,可以选择二进制安装方式)

5.初始化数据库

创建my.cnf配置文件

[root@xin 3306]# vim my.cnf

[client]  

port=3306  

socket=/usr/mysql/mysql_data/3306/mysql.sock  

  

[mysqld_safe]  

log-error=/usr/mysql/mysql_data/3306/mysql.err  

pid-file=/usr/mysql/mysql_data/3306/mysql.pid  

  

[mysqld]  

server-id=1  

log-bin=/usr/mysql/mysql_data/3306/mysql-bin  

user= mysql  

pid-file=/usr/mysql/mysql_data/3306/mysql.pid  

socket=/usr/mysql/mysql_data/3306/mysql.sock  

port=3306  

basedir=/usr/mysql

datadir=/usr/mysql/mysql_data/3306/data  

tmpdir=/tmp  

open_files_limit=1024  

external-locking = false  

character-set-server=utf8  

default-storage-engine=MyISAM  

  

bind-address= 0.0.0.0  

max_allowed_packet= 8M  

thread_stack= 192K  

thread_cache_size= 8  

  

max_connections= 800  

max_connect_errors= 300  

#table_cache= 64  

#thread_concurrency= 10  

  

query_cache_limit=1M  

query_cache_size=2M  

join_buffer_size=1M  

sort_buffer_size=1M  

  

long_query_time = 1  

relay-log = /usr/mysql/mysql_data/3306/relay-bin  

relay-log-info-file =/usr/mysql/mysql_data/3306/relay-log.info  

binlog_cache_size = 1M  

max_binlog_cache_size = 1M  

max_binlog_size = 2M  

key_buffer_size=16M  

read_buffer_size = 1M  

read_rnd_buffer_size = 1M  

bulk_insert_buffer_size = 1M  

lower_case_table_names = 1  

skip-name-resolve  

slave-skip-errors =1032,1062  

replicate-ignore-db = mysql  

#innodb_additional_mem_pool_size = 4M  

innodb_buffer_pool_size = 32M  

innodb_data_file_path = ibdata1:12M:autoextend  

#innodb_file_io_threads = 4  

innodb_thread_concurrency = 8  

innodb_flush_log_at_trx_commit = 2  

innodb_log_buffer_size = 2M  

innodb_log_file_size = 4M  

#innodb_log_files_in_groups = 3  

innodb_max_dirty_pages_pct = 90  

innodb_lock_wait_timeout = 120  

innodb_file_per_table = 0  

[mysqldump]  

quick  

quote-names  

max_allowed_packet=16M

添加mysql系统用户

[root@xin mysql-5.7.19]# useradd mysql–M -r -s /sbin/nologin 

添加操作文件权限
[root@xin mysql-5.7.19]# chmod 766 /usr/mysql/mysql_data/3306/mysql.err 

创建MySQL启动文件

[root@xin 3306]# vim mysql

#!/bin/sh  

port=3306  

mysql_user="root"  

mysql_pwd="weixin123456"  

cmd_path="/usr/mysql/bin"  

mysql_sock="/usr/mysql/mysql_data/${port}/mysql.sock"  

  

#startup function  

function_start_mysql()  

{  

    if [ ! -e "$mysql_sock" ];then  

      printf "Starting MySQL...\n"  

      /bin/sh ${cmd_path}/mysqld_safe --defaults-file=/usr/mysql/mysql_data/${port}/my.cnf 2>&1 > /dev/null &  

    else  

      printf "MySQL is running...\n"  

      exit  

    fi  

}  

#stop function  

function_stop_mysql()  

{  

    if [ ! -e "$mysql_sock" ];then  

       printf "MySQL is stopped...\n"  

       exit  

    else  

       printf "Stoping MySQL...\n"  

       ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /usr/mysql/mysql_data/${port}/mysql.sock shutdown  

   fi  

}  

#restart function  

function_restart_mysql()  

{  

    printf "Restarting MySQL...\n"  

    function_stop_mysql  

    sleep 2  

    function_start_mysql  

}  

case $1 in  

start)  

    function_start_mysql  

;;  

stop)  

    function_stop_mysql  

;;  

restart)  

    function_restart_mysql  

;;  

*)  

    printf "Usage: /usr/mysql/mysql_data/${port}/mysql {start|stop|restart}\n"  

esac  

添加操作文件权限

[root@xin 3306]# chmod 755 /usr/mysql/mysql_data/3306/mysql

添加文件夹的操作权限

[root@xin 3306]# chown –R mysql:mysql /usr/mysql

执行初始化命令,记录临时密码

[root@xin 3306]# /usr/mysql/bin/mysqld --initialize  --basedir=/usr/mysql --datadir=/usr/mysql/mysql_data/3306/data  --user=mysql

启动实例

[root@xin 3306]# /usr/mysql/mysql_data/3306/mysql start

查看是否已启动

[root@localhost ~]# netstat -lntp | grep mysql  

tcp        0      0 0.0.0.0:3307            0.0.0.0:*               LISTEN      4480/mysqld 

登陆实例

[root@localhost ~]#  cd  /usr/mysql  //切换到mysql的安装目录

[root@xin mysql]#  ./bin/mysql -u root -p -S ./mysql_data/3306/mysql.sock

Enter password:

重新设置密码

mysql> SET PASSWORD = PASSWORD('your_password');  

Query OK, 0 rows affected (0.03 sec) 

开启远程访问

mysql> grant all privileges on *.* to 'root'@'%' identified by 'weixin123456' with grant option;  
Query OK, 0 rows affected (0.03 sec) 

mysql> flush privileges;  

Query OK, 0 rows affected (0.03 sec)

开放防火墙端口

 [root@xin mysql]#  vi   /etc/sysconfig/iptables

编辑iptables文件,添加开放端口

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

重启防火墙

 [root@xin mysql]#  service iptables restart

至此端口为3306的mysql实例已经创建完了,若要创建3307、3308等,重复5步骤即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: