MySQL多端口安装简介

MySQL多端口安装简介

MySQL多端口安装简介
(图片来源网络,侵删)

在计算机系统中,为了提高数据库服务器的安全性和性能,我们通常会为MySQL设置多个端口,这样,不同的应用程序或用户就可以通过不同的端口连接到MySQL服务器,实现数据的访问和操作,本文将详细介绍如何在Linux系统上安装并配置MySQL多端口。

准备工作

1、下载MySQL安装包

访问MySQL官方网站(https://dev.mysql.com/downloads/mysql/)下载适合你的操作系统的MySQL安装包。

2、安装依赖库

在安装MySQL之前,需要先安装一些依赖库,以Ubuntu为例,可以使用以下命令安装:

sudo aptget update
sudo aptget install libaio1

安装MySQL

1、解压安装包

将下载的MySQL安装包解压到一个目录,例如/usr/local/mysql

tar zxvf mysql8.0.26linuxglibc2.12x86_64.tar.gz C /usr/local/

2、创建MySQL用户和组

为了安全起见,我们需要创建一个专门的用户和组来运行MySQL服务:

sudo groupadd mysql
sudo useradd r g mysql s /bin/false mysql

3、更改MySQL目录权限

将MySQL目录的属主和属组更改为刚刚创建的用户和组:

sudo chown R mysql:mysql /usr/local/mysql

4、初始化MySQL数据库

进入MySQL目录,执行初始化脚本:

cd /usr/local/mysql
sudo bin/mysqld initialize user=mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data pidfile=/usr/local/mysql/data/mysqld.pid socket=/usr/local/mysql/data/mysqld.sock port=3307 logerror=/usr/local/mysql/data/mysqld.err lcmessagesdir=/usr/local/mysql/data skipexternallocking bindaddress=0.0.0.0 enforcestorageengine=MyISAM sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_UNREFERENCED_TABLE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,NO_CHECK_LOACAL_INFILE,NO_AUTO_CREATE_USER,NO_ENGINE_UNREFERENCED_TABLE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,NO_CHECK_LOACAL_INFILE,NO_AUTO_CREATE_USER,NO_ENGINE_UNREFERENCED_TABLE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,NO_CHECK_LOACAL_INFILE securefilepriv="/usr/local/mysql/data" charactersetserver=utf8mb4 collationserver=utf8mb4_unicode_ci explicit_defaults_for_timestamp=true lowercasetablenames=1 skipsymboliclinks skipshowdatabases skipcomments skiplogwarnings skipmultiplexing enablelocalinfile pluginload=partition serverid=1 maxheaptablesize=128M tmpdir=/usr/local/tmp maxallowedpacket=16M openfileslimit=50000 tabledefinitioncache=4096 tableopencache=4096 concurrentinsert = 2 querycachetype = 1 querycachesize = 64M threadcachesize = 50 myisamrecovery = FORCE,BACKUP keybuffer = 32M readbuffer = 2M writebuffer = 2M sort buffer = 2M join buffer = 2M readrndbuffer = 256K bulk insert buffer = 64M netbuffer = 8K maxallowedpacket = 16M maxconnectableclients = 1000000000 maxconnections = 500000000 maxdelayedthreads = 1000000000 maxheap = 128M maxrelaylog = 524288000 maxupdated = 524288000 maxuserconnections = 1000000000;

5、启动MySQL服务

使用以下命令启动MySQL服务:

sudo bin/mysqld start user=mysql &

配置MySQL多端口

1、修改配置文件

打开MySQL配置文件my.cnf,找到[mysqld]部分,添加以下内容:

[mysqld]
port            = 3307 # 默认端口号为3306,这里设置为3307,表示第二个端口号为3307,你可以根据需要设置更多的端口号。

2、重启MySQL服务

使用以下命令重启MySQL服务,使配置生效:

sudo service mysql restart | sudo /etc/init.d/mysql restart | sudo systemctl restart mysqld | sudo systemctl stop firewalld | sudo systemctl disable firewalld | sudo systemctl start firewalld | sudo systemctl enable firewalld | netstat anp | grep "LISTEN" | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc/sysconfig/iptables | grep ":3307" | tail n +2 > /etc

原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/503850.html

本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。

(0)
未希新媒体运营
上一篇 2024-04-22 23:27
下一篇 2024-04-22 23:28

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

产品购买 QQ咨询 微信咨询 SEO优化
分享本页
返回顶部
云产品限时秒杀。精选云产品高防服务器,20M大带宽限量抢购 >>点击进入