在原有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 一.免密登陆操 ...
随机推荐
- 学习HashMap源码
HashMap简介 HashMap是一种存储K-V类型的容器,HashMap底层数据结构为数组+链表+红黑树(jdk 1.8新增),它根据键的HashCode值存储数据,获取元素的时间复杂度为O( ...
- python连接mongodb数据库
之前使用过python连接mysql数据库(用到pymysql库),公司也有使用mongodb数据库,所以就整理了一份python连接mongodb数据库的代码出来,以供记录和分享. 首先我们要用到 ...
- 【论文阅读】CVPR2022: Learning from all vehicles
Column: March 23, 2022 1:08 PM Last edited time: March 23, 2022 11:13 PM Sensor/组织: 现leaderboard第一名, ...
- 通过Kuberneters Goat学习K8S安全(上)
实验环境:https://katacoda.com/madhuakula/scenarios/kubernetes-goat 0x1.敏感信息泄露利用 第一关是代码泄露利用,打开网站后显示: 告诉我们 ...
- 查找bug的一些经验总结
项目开发中遇到的bug解决经验总结 今天在项目开发中遇到了两个很难解决的bug,我把我的思路记录下来,以供之后遇到bug时,提供一些思路: 编译通过,但总结"core dumped" ...
- oracle 跨分区查询效率,Oracle分区表做跨分区查询
问:有一张大表,其中按时间字段(TIME_ID)进行表分区(按季度分区),但是如果业务人员做跨季度的大批量数据的查询时,未能走TIME_ID分区索引,导致全表扫描.此种情况该如何处理? 示例解析: 1 ...
- win10 doskey宏命令定义,类似于Linux的alias别名命令
doskey 命令别名=命令 例如:doskey echo2 = echo $1 这里的$1是占位符. 如果想删除,直接赋予空值即可:例如:doskey echo2= 总的来说把 https://do ...
- Zookeeper 文件系统 ?
Zookeeper 提供一个多层级的节点命名空间(节点称为 znode).与文件系统不 同的是,这些节点都可以设置关联的数据,而文件系统中只有文件节点可以存放 数据而目录节点不行. Zookeeper ...
- BeanFactory – BeanFactory 实现举例?
Bean 工厂是工厂模式的一个实现,提供了控制反转功能,用来把应用的配置和依赖从正真的应用代码中分离. 最常用的BeanFactory 实现是XmlBeanFactory 类.
- XMLBeanFactory?
最常用的就是org.springframework.beans.factory.xml.XmlBeanFactory ,它根据XML文件中的定义加载beans.该容器从XML 文件读取配置元数据并用它 ...