采用的是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. Linux企业常用命令详解

    cat :查看 cat [-AbeEnstTuv] [--help] [--version] fileName 常用参数: -n :由 1 开始对所有输出的行数编号 -b :和 -n 相似,对于空白行 ...

  2. Apple macOS Mojave Intel Graphics Driver组件任意代码执行漏洞

    受影响系统:Apple macOS Mojave 10.14.5描述:CVE(CAN) ID: CVE-2019-8629 Apple macOS Mojave是苹果公司Mac电脑系列产品的操作系统. ...

  3. 6月21日 Django ORM那些相关操作(表关联、聚合查询和分组查询)

    一.ForeignKey操作 正向查找 对象查找(跨表) 语法: 对象.关联字段.字段   示例: book_obj = models.Book.objects.first() # 第一本书对象 pr ...

  4. Java的自动装箱与拆箱(Autoboxing and unboxing)

    一.什么是自动装箱拆箱 很简单,下面两句代码就可以看到装箱和拆箱过程 1 //自动装箱 2 Integer total = 99; 3 4 //自动拆箱 5 int totalprim = total ...

  5. 判断一文件是不是字符设备文件,如果是将其拷贝到 /dev 目录下?

    #!/bin/bashread -p "Input file name: " FILENAMEif [ -c "$FILENAME" ];then cp $FI ...

  6. httpRunner使用小结

    1.每个系统可以给所有相关接口准备一份完整的主流程数据,这样就不用每执行一条用例就要先执行很多前置用例2.每条用例在设计之初,关于使用的前置数据,以及条件判断的数据值,以及设置的前提条件数据值,尽量保 ...

  7. JavaScript的访问器

    一.访问器属性: 1.Configurable:表示能否通过delete删除属性,从而重新定义属性,能否修改属性的特性,或者能否把属性修改为数据属性.对于直接在对象上定义的属性,这个特性的默认值为tr ...

  8. redis 淘汰策略有哪些?

    noeviction: 不删除策略, 达到最大内存限制时, 如果需要更多内存, 直接返回错误信息. 大多数写命令都会导致占用更多的内存(有极少数会例外, 如 DEL ). allkeys-lru: 所 ...

  9. MariaDB ZIP方式安装(Window系统)

    Maria DB ZIP方式安装 Windows上ZIP包的入门非常简单-此发行版包括预构建的数据库文件,这些文件可以在解压缩ZIP后立即使用. 您可以从命令提示符运行mysqld.exe,如下所示: ...

  10. 有哪些类型的通知(Advice)?

    Before - 这些类型的 Advice 在 joinpoint 方法之前执行,并使用 @Before 注解标记进行配置. After Returning - 这些类型的 Advice 在连接点方法 ...