采用的是yum install mysql-community-server yum方式安装mysql(社区版) 文章基础上新加一个mysql实例。
   这个完全可以直接实战上应用,只要规划好即可
   服务器上已经安装了3306端口的mysql服务,需要再启一个3307端口的mysql服务。(我们云上不少服务器都是安装的多实例,不过要慎重,特别对于重要服务来说,最好单独设计架构)
   
一、准备:

 1、建立data目录
[root@fp-web-118 3307]# mkdir /data
[root@fp-web-118 3307]# mkdir /data/3307/data
[root@fp-web-118 3307]# mkdir /data/3307/log
        [root@fp-web-118 3307]# touch /data/3307/log/mysqld.log
         [root@fp-web-118 3307]#chown -R mysql:mysql /data/3307
2、复制mysql配置文件到3307目录下进行修改
[root@fp-web-118 3307]# cp /etc/my.cnf /data/3307

二、编辑my.cnf

[root@fp-web-118 3307]# vi my.cnf

[client]
character-set-server = utf8
port    = 3307
socket  = /data/3307/mysql_3307.sock

[mysqld]
user=mysql
port=3307   ###这里很重要,否则mysql启动的时候会找3306端口
datadir=/data/3307/data  ###这里也不能设置错,否则日志都输出不出来
socket=/data/3307/mysql.sock

symbolic-links=0

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /usr/  ##这里就是你当初安装mysql的路径,一般是/usr/local/mysql,或者是/data/mysql等,yum或rpm是/usr

[mysqld_safe]
log-error=/data/3307/log/mysqld.log
pid-file=/data/3307/mysqld_3307.pid
##basedir 如果不知道可以查看之前启动的 ps -efww| grep mysql

注:这里是基本配置,可以在这个基础上增加相关配置参数。

三、数据库的初始化:

# 5.7.6之前初始化的方法是:mysql_install_db

#5.7.6之后的版本初始化数据库不再使用mysql_install_db,而是使用: bin/mysqld --initialize
这里机器上安装的是5.6版本mysql,yum方式

[root@fp-web-118 data]# mysql_install_db --defaults-file=/data/3307/my.cnf --datadir=/data/3307/data

执行过程如下:

Installing MySQL system tables...2022-02-01 21:26:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-02-01 21:26:46 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2022-02-01 21:26:46 0 [Note] /usr/sbin/mysqld (mysqld 5.6.51) starting as process 78101 ...
2022-02-01 21:26:46 78101 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-02-01 21:26:46 78101 [Note] InnoDB: The InnoDB memory heap is disabled
2022-02-01 21:26:46 78101 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-02-01 21:26:46 78101 [Note] InnoDB: Memory barrier is not used
2022-02-01 21:26:46 78101 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-02-01 21:26:46 78101 [Note] InnoDB: Using Linux native AIO
2022-02-01 21:26:46 78101 [Note] InnoDB: Using CPU crc32 instructions
2022-02-01 21:26:46 78101 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2022-02-01 21:26:46 78101 [Note] InnoDB: Completed initialization of buffer pool
2022-02-01 21:26:46 78101 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2022-02-01 21:26:46 78101 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2022-02-01 21:26:46 78101 [Note] InnoDB: Database physically writes the file full: wait...
2022-02-01 21:26:46 78101 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2022-02-01 21:26:47 78101 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2022-02-01 21:26:47 78101 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2022-02-01 21:26:47 78101 [Warning] InnoDB: New log files created, LSN=45781
2022-02-01 21:26:47 78101 [Note] InnoDB: Doublewrite buffer not found: creating new
2022-02-01 21:26:47 78101 [Note] InnoDB: Doublewrite buffer created
2022-02-01 21:26:47 78101 [Note] InnoDB: 128 rollback segment(s) are active.
2022-02-01 21:26:47 78101 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-02-01 21:26:47 78101 [Note] InnoDB: Foreign key constraint system tables created
2022-02-01 21:26:47 78101 [Note] InnoDB: Creating tablespace and datafile system tables.
2022-02-01 21:26:47 78101 [Note] InnoDB: Tablespace and datafile system tables created.
2022-02-01 21:26:47 78101 [Note] InnoDB: Waiting for purge to start
2022-02-01 21:26:47 78101 [Note] InnoDB: 5.6.51 started; log sequence number 0
2022-02-01 21:26:47 78101 [Note] RSA private key file not found: /data/3307/data//private_key.pem. Some authentication plugins will not work.
2022-02-01 21:26:47 78101 [Note] RSA public key file not found: /data/3307/data//public_key.pem. Some authentication plugins will not work.
2022-02-01 21:26:48 78101 [Note] Binlog end
2022-02-01 21:26:48 78101 [Note] InnoDB: FTS optimize thread exiting.
2022-02-01 21:26:48 78101 [Note] InnoDB: Starting shutdown...
2022-02-01 21:26:49 78101 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2022-02-01 21:26:49 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-02-01 21:26:49 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2022-02-01 21:26:49 0 [Note] /usr/sbin/mysqld (mysqld 5.6.51) starting as process 78127 ...
2022-02-01 21:26:49 78127 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-02-01 21:26:49 78127 [Note] InnoDB: The InnoDB memory heap is disabled
2022-02-01 21:26:49 78127 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-02-01 21:26:49 78127 [Note] InnoDB: Memory barrier is not used
2022-02-01 21:26:49 78127 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-02-01 21:26:49 78127 [Note] InnoDB: Using Linux native AIO
2022-02-01 21:26:49 78127 [Note] InnoDB: Using CPU crc32 instructions
2022-02-01 21:26:49 78127 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2022-02-01 21:26:49 78127 [Note] InnoDB: Completed initialization of buffer pool
2022-02-01 21:26:49 78127 [Note] InnoDB: Highest supported file format is Barracuda.
2022-02-01 21:26:49 78127 [Note] InnoDB: 128 rollback segment(s) are active.
2022-02-01 21:26:49 78127 [Note] InnoDB: Waiting for purge to start
2022-02-01 21:26:49 78127 [Note] InnoDB: 5.6.51 started; log sequence number 1625977
2022-02-01 21:26:49 78127 [Note] RSA private key file not found: /data/3307/data//private_key.pem. Some authentication plugins will not work.
2022-02-01 21:26:49 78127 [Note] RSA public key file not found: /data/3307/data//public_key.pem. Some authentication plugins will not work.
2022-02-01 21:26:49 78127 [Note] Binlog end
2022-02-01 21:26:49 78127 [Note] InnoDB: FTS optimize thread exiting.
2022-02-01 21:26:49 78127 [Note] InnoDB: Starting shutdown...
2022-02-01 21:26:51 78127 [Note] InnoDB: Shutdown completed; log sequence number 1625987
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:

/usr/bin/mysqladmin -u root password 'new-password'  ##这里是有价值的信息
/usr/bin/mysqladmin -u root -h fp-web-118 password 'new-password' ##这里是有价值的信息

Alternatively you can run:

/usr/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 /usr ; /usr/bin/mysqld_safe &    ##这里是有价值的信息

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

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

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file /usr/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/my-new.cnf,
please compare it with your file and take the changes you need.

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

编写启动脚本,放在data/3307下,起名叫 mysql_start_my

#!/bin/sh
#init
#mysql_user=root
#mysql_pwd=123
port=3307
CmdPath="/usr/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
isrun=`ps -ef | grep ${mysql_sock}|grep -v grep|wc -l`

function_start_mysql()
{
if [ ! -e "$mysql_sock" ] || [ ${isrun} -eq 0 ];then
printf "Starting MySQL...\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/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"
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /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: /data/${port}/mysql {start|stop|restart}\n"
esac

改变权限和所属
[root@fp-web-118 3307]# chown mysql:mysql mysql_start_my
[root@fp-web-118 3307]# chmod 775mysql_start_my

启动3307myql

[root@fp-web-118 3307]# ./mysql_start_my start
Starting MySQL...

查看tcp端口
[root@fp-web-118 3307]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:6443 *:*
LISTEN 0 8 *:179 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 64 *:26684 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 80 :::3307 :::*
LISTEN 0 128 :::9099 :::*
LISTEN 0 64 :::24854 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 :::10050 :::*

登录3307端口

[root@fp-web-118 3307]# mysql -uroot -p -S /data/3307/mysql.sock
Enter password:    ##初始化默认为空
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql> show variables like 'port';  ##查看启动端口
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3307 |
+---------------+-------+
1 row in set (0.00 sec)

登录3306端口

[root@fp-web-118 3307]# mysql -u root -h fp-web-118 -pjinzs

Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)

在原有mysql机器上增加一台实例的更多相关文章

  1. linux机器上部署多台Tomcat

    在Linux机器上部署多台Tomcat, 我部署的是Tomcat8,只需要一步,即避免端口号冲突. 在解压后的tomcat目录下,修改conf下server.xml. 修改shutdown端口: &l ...

  2. 修改struts2自定义标签的源代码,在原有基础上增加功能(用于OA项目权限判断,是否显示某个权限)

    OA项目在做权限判断时  原始方式: 现在完成的功能 :通过改变struts2自定标签源代码   在原有的基础上  增加判断权限的功能  而页面上使用标签的方式 还是下图 步骤: 打开文件 搜索< ...

  3. 如何在同一台机器上安装多个MySQL的实例

    转自:'http://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的 ...

  4. 如何在同一台机器上安装多个MySQL的实例 转

    https://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的MyS ...

  5. 如何在同一台机器上安装多个MySQL的实例(转)

    最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的MySQL的实例). 先说下,什么是mysql的多实例,简单的来说就是一台机器上安装了多个mysql的服务 ...

  6. 解决mysql跟php不在同一台机器上,编译安装php服务报错问题:configure: error: Cannot find MySQL header files under /application/mysql.

    在编译安装php服务时报错: configure: error: Cannot find MySQL header files under /application/mysql. Note that ...

  7. MySQL 8 在一台机器上运行多个MySQL实例

    可以为每个实例使用一个MySQL Server二进制程序,也可以为不同实例使用同一个MySQL Server二进制程序. 不管哪一种选择,部分参数可能需要不同配置,以避免多个实例之间的冲突. 可能需要 ...

  8. 用pf透明地将流量从一台机器转到另一台机器上的缘起及实现方式对比

    下面是也是我在12580工作时发生的事情,重新记录并发出来.这种特殊需求很考 验PF的功底.在新旧系统并存,做重构的时候有时很需要这种救急的作法.一.缘起miscweb1(172.16.88.228) ...

  9. shell远程操作另外一台机器上数据

    shell远程操作另外一台机器上的数据,有两种方式: 1 .配置免密登陆,2.使用sshpass 当前存在两台虚拟机,ip地址分别为:192.168.3.32 192.168.3.33 一.免密登陆操 ...

随机推荐

  1. CentOS 5.11源修改

    CentOS 5.11源 将源中所有网址替换为 http://archive.kernel.org/centos-vault/你的版本/ 一条sed命令即可解决 sed -i 's@http://xx ...

  2. 前端面试题(css)

    css  基础面试题 css 面试题 js 面试题 1.介绍下CSS的盒子模型    介绍一下标准的CSS的盒子模型?与低版本IE的盒子模型有什么不同的? css 是如何设置这两种模型的 box-si ...

  3. 初探 Elasticsearch,学习笔记第一讲

          1. ES 基础   1.1 ES定义   ES=elaticsearch简写, Elasticsearch是一个开源的高扩展的分布式全文检索引擎,它可以近乎实时的存储.检索数据:本身扩展 ...

  4. Linux项目部署 jdk tomcat 安装配置 linux下 failed connect to localhost:8080;Connection refused

         ONBOOT=yes 5.安装wget (1)安装 yum -y install wget (2) 查看版本  wget --version或 wget -V 一.安装jdk 配置 (1)安 ...

  5. Java 代码注意细节

    代码优化的目标是: 1.减小代码的体积 2.提高代码运行的效率 代码优化细节 1.尽量指定类.方法的final修饰符 带有final修饰符的类是不可派生的.在Java核心API中,有许多应用final ...

  6. 网络监听FTP明文口令实验

    一. 开启环境 1.登录FTP服务器. 2.启动FTP服务器 (1)打开FTP服务器.点击最左面绿色按钮,启动ftp服务器. (2)可以看到以下变化:ftp服务器启动.显示"FTP服务在线& ...

  7. Kernel Pwn基础教程之 Double Fetch

    一.前言 Double Fetch是一种条件竞争类型的漏洞,其主要形成的原因是由于用户态与内核态之间的数据在进行交互时存在时间差,我们在先前的学习中有了解到内核在从用户态中获取数据时会使用函数copy ...

  8. 题解0005:数的划分(洛谷P1025)

    题目描述:将整数 n 分成 k 份,每份不能为空,颠倒顺序的被看成一种分法. 题目链接:https://www.luogu.com.cn/problem/P1025 题目思路:深搜剪枝,规定搜索的下一 ...

  9. 初识$router和$route

    初识\(router和\)route 一.前言 ​ vue框架中单页面富应用可以说是其最大的优点功能之一了,应用起来简单直观,说起单页面富应用那就必须得联想到\(router**,但是在项目开发过程中 ...

  10. netcore后台任务注意事项

    开局一张图,故事慢慢编!这是一个后台任务打印时间的德莫,代码如下: using BackGroundTask; var builder = WebApplication.CreateBuilder() ...