mysql5.7多实例

启动端口号为3355和3366的二个实例。创建文件夹

 

[root@localhost /]# mkdir -p /mysqldata/{3355,3366}/data

 

将配置文件拷贝到响应的文件夹,

my.cnf

 

[client]
port            = 3355
socket          = /mysqldata/3355/mysql.sock

[mysql]
no-auto-rehash

[mysqld]
user    = mysql
port    = 3355
socket  = /mysqldata/3355/mysql.sock
basedir = /mysql
datadir = /mysqldata/3355/data
open_files_limit    = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k

 

 

[root@localhost 3306]# cp my.cnf /mysqldata/3355/

[root@localhost 3306]# cp my.cnf /mysqldata/3356

编辑端口号

[root@localhost mysqldata]# vim /mysqldata/3366/my.cnf

[root@localhost mysqldata]# vim /mysqldata/3366/my.cnf

 

创建数据库目录

 

[root@localhost /]# /mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/mysqldata/3355/data

[root@localhost /]# /mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/mysqldata/3366/data

 

编写启动脚本

 

 

#!/bin/sh

port=3355
mysql_user="root"
mysql_pwd="123456"
Cmd_path="/mysql/bin"
mysql_sock="/mysqldata/${port}/mysql.sock"

function_start_mysql()
{
 if [ ! -e "$mysql_sock" ];then
  printf "Starting MySQL\n"
  /bin/sh ${Cmd_path}/mysqld_safe --defaults-file=/mysqldata/${port}/my.cnf  &
 else
  print "MySQL is running..\n"
  exit
 fi
}

function_stop_mysql()
{
  if [ !-e "$mysql_sock" ];then
   printf "MYSQL IS NOT RUNNING \n"
   exit
  else
   ${Cmd_path}/mysqladmin -u${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
   printf "MYSQL IS shutdown \n"
  fi

}

function_restart_mysql()
{
  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: /data/${port}/mysql {start|stop|restart}\n"
;;
esac

 

 

[root@localhost /]# cp /mysqldata/3355/mysql /mysqldata/3366/

进行端口号修改

 

 

修改mysqldata的归属

 

[root@localhost /]# chown -R mysql.mysql /mysqldata/

 

给脚本增加执行权限

[root@localhost /]# chmod +x /mysqldata/3355/mysql 

[root@localhost /]# chmod +x /mysqldata/3366/mysql   

[root@localhost /]# ls -l /mysqldata/33*/mysql           

-rwxr-xr-x 1 mysql mysql 827 Sep 27 07:58 /mysqldata/3355/mysql

-rwxr-xr-x 1 mysql mysql 827 Sep 27 07:58 /mysqldata/3366/mysql

运行多实例

[root@localhost /]# ./mysqldata/3355/mysql start

[root@localhost /]# ./mysqldata/3366/mysql start

查看一下

[root@localhost mysqldata]# ps -ef|grep mysql

root     14694     1  0 08:08 pts/1    00:00:00 /bin/sh /mysql/bin/mysqld_safe --defaults-file=/mysqldata/3355/my.cnf

mysql    14981 14694  0 08:08 pts/1    00:00:00 /mysql-5.7.15/bin/mysqld --defaults-file=/mysqldata/3355/my.cnf --basedir=/mysql --datadir=/mysqldata/3355/data --plugin-dir=/mysql/lib/plugin --user=mysql --log-error=/mysqldata/3355/data/localhost.localdomain.err --open-files-limit=1024 --pid-file=/mysqldata/3355/data/localhost.localdomain.pid --socket=/mysqldata/3355/mysql.sock --port=3355

root     15064     1  0 08:10 pts/1    00:00:00 /bin/sh /mysql/bin/mysqld_safe --defaults-file=/mysqldata/3366/my.cnf

mysql    15351 15064  3 08:10 pts/1    00:00:00 /mysql-5.7.15/bin/mysqld --defaults-file=/mysqldata/3366/my.cnf --basedir=/mysql --datadir=/mysqldata/3366/data --plugin-dir=/mysql/lib/plugin --user=mysql --log-error=/mysqldata/3366/data/localhost.localdomain.err --open-files-limit=1024 --pid-file=/mysqldata/3366/data/localhost.localdomain.pid --socket=/mysqldata/3366/mysql.sock --port=3366

 

看看端口号

[root@localhost /]# netstat -an|grep 33[55-66]

tcp6       0      0 :::3355                 :::*                    LISTEN     

tcp6       0      0 :::3366                 :::*                    LISTEN     

unix  2      [ ACC ]     STREAM     LISTENING     94457    /mysqldata/3355/mysql.sock

unix  2      [ ACC ]     STREAM     LISTENING     94854    /mysqldata/3366/mysql.sock

你可能感兴趣的:(mysql)