在原有mysql机器上增加一台实例
采用的是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机器上增加一台实例的更多相关文章
- linux机器上部署多台Tomcat
在Linux机器上部署多台Tomcat, 我部署的是Tomcat8,只需要一步,即避免端口号冲突. 在解压后的tomcat目录下,修改conf下server.xml. 修改shutdown端口: &l ...
- 修改struts2自定义标签的源代码,在原有基础上增加功能(用于OA项目权限判断,是否显示某个权限)
OA项目在做权限判断时 原始方式: 现在完成的功能 :通过改变struts2自定标签源代码 在原有的基础上 增加判断权限的功能 而页面上使用标签的方式 还是下图 步骤: 打开文件 搜索< ...
- 如何在同一台机器上安装多个MySQL的实例
转自:'http://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的 ...
- 如何在同一台机器上安装多个MySQL的实例 转
https://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的MyS ...
- 如何在同一台机器上安装多个MySQL的实例(转)
最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的MySQL的实例). 先说下,什么是mysql的多实例,简单的来说就是一台机器上安装了多个mysql的服务 ...
- 解决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 ...
- MySQL 8 在一台机器上运行多个MySQL实例
可以为每个实例使用一个MySQL Server二进制程序,也可以为不同实例使用同一个MySQL Server二进制程序. 不管哪一种选择,部分参数可能需要不同配置,以避免多个实例之间的冲突. 可能需要 ...
- 用pf透明地将流量从一台机器转到另一台机器上的缘起及实现方式对比
下面是也是我在12580工作时发生的事情,重新记录并发出来.这种特殊需求很考 验PF的功底.在新旧系统并存,做重构的时候有时很需要这种救急的作法.一.缘起miscweb1(172.16.88.228) ...
- shell远程操作另外一台机器上数据
shell远程操作另外一台机器上的数据,有两种方式: 1 .配置免密登陆,2.使用sshpass 当前存在两台虚拟机,ip地址分别为:192.168.3.32 192.168.3.33 一.免密登陆操 ...
随机推荐
- java 网络编程之Socket编程
1.客户端代码 1 package com.gylhaut.socket; 2 3 import java.io.BufferedReader; 4 import java.io.IOExcept ...
- xssgame记录
xss地址:http://www.xssgame.com/ 直接插入标签 构造语句,注意闭合 注意寻找输出点,这个会进行一次urlencode,和浏览器有关系,firefox过不了 javascrip ...
- sql注入之简要注入
#mysql简要注入流程 mysql注入简要流程如下图: 由于还没学习完先结合sqlilabs的第一关讲解信息收集的一部分和数据注入的information_schema的有据查询. #sqli-la ...
- [USACO08OPEN]牛的街区Cow Neighborhoods
题目描述: luogu 题解: 技巧题. 曼哈顿距离:$|x1-x2|+|y1-y2|$ 切比雪夫距离:$\max(|x1-x2|,|y1-y2|)$ 曼哈顿距离转切比雪夫距离:$(x,y)-> ...
- 你应该知道的Redis事务
前两篇 Redis 文章都大几千字,今天我们换个小清新点的 如果你也了解过关系型数据库事务的话,相信这篇文章对你来说是很容易理解的了.具体什么是事务我就不说不多了,直接讲 Redis 事务相关的部分. ...
- 生产环境频繁内存溢出,原来就是因为这个“String类”
摘要:如果在程序中创建了比较大的对象,并且我们基于这个大对象生成了一些其他的信息,此时,一定要释放和这个大对象的引用关系,否则,就会埋下内存溢出的隐患. 本文分享自华为云社区<[高并发]你敢信? ...
- Redis 常见的性能问题都有哪些?如何解决?
Redis 常见的性能问题都有哪些?如何解决? Master写内存快照,save命令调度rdbSave函数,会阻塞主线程的工作,当快照比较大时对性能影响是非常大的,会间断性暂停服务,所以Master最 ...
- GC root & 使用MAT分析java堆
当我们的java程序遇到频繁full gc或者oom的时候,我们常常需要将当前的heap dump出来进行进一步的分析.MAT是用于分析heap dump的神器. 1 生成heap dump heap ...
- 什么是 Idempotence 以及它在哪里使用?
幂等性是能够以这样的方式做两次事情的特性,即最终结果将保持不变,即好像 它只做了一次. 用法:在远程服务或数据源中使用 Idempotence,这样当它多次接收指令时,它 只处理指令一次.
- 什么是 CAS?
CAS 是 compare and swap 的缩写,即我们所说的比较交换. cas 是一种基于锁的操作,而且是乐观锁.在 java 中锁分为乐观锁和悲观锁.悲观锁是将资源锁住,等一个之前获得锁的线程 ...