当前位置: 首页 > article >正文

MySQL集群技术1——编译部署mysql

MySQL在服务器中的部署办法

一般而言,企业中的服务器操作系统都为linux,对于MySQL的安装则通常采用源码编译的方式来进行。

MySQL 是一个广泛使用的开源关系型数据库管理系统。如果您希望从源代码编译和安装 MySQL,可以遵循以下步骤。请注意,这里假设您正在使用类 Unix 系统(如 Linux 或 macOS),并且您具有 root 或 sudo 访问权限。

准备工作

  1. 更新系统包列表

    sudo apt update
    
  2. 安装必要的依赖包

    sudo apt install build-essential cmake libncurses5-dev libssl-dev libaio1 libaio-dev libreadline-dev bison flex libmysqlclient-dev libncursesw5-dev liblz4-tool
    
  3. 创建安装目录

    mkdir -p /usr/local/mysql
    

下载源代码

  1. 访问 MySQL 官方网站:前往 MySQL 的官方下载页面获取最新版本的源代码包。

  2. 下载源代码包:使用 wget 或 curl 下载源代码包。

    wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.33.tar.gz
    
  3. 解压缩源代码包

    tar xzf mysql-8.0.33.tar.gz
    

配置和编译

  1. 进入源代码目录

    cd mysql-8.0.33
    
  2. 创建构建目录

    mkdir build
    cd build
    
  3. 配置编译选项

    cmake \
      -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
      -DWITH_INNOBASE_STORAGE_ENGINE=1 \
      -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
      -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
      -DWITH_READLINE=1 \
      -DWITH_ZLIB=bundled \
      -DWITH_LZ4=bundled \
      -DWITH_ZSTD=bundled \
      -DWITH_PERFD_SCHEMA=1 \
      -DWITH_INNOBASE_SUPPORT_XA=1 \
      -DWITH_EXTRA_CHARSETS=all \
      -DENABLED_LOCAL_INFILE=1 \
      -DDEFAULT_CHARSET=utf8mb4 \
      -DDEFAULT_COLLATION=utf8mb4_unicode_ci \
      -DWITH_SSL=yes \
      -DWITH_DEBUG=0 \
      -DWITH_BOOST=/usr \
      -DMYSQL_DATADIR=/usr/local/mysql/data \
      -DINSTALL_MANDIR=/usr/local/mysql/share/man \
      -DINSTALL_DOCDIR=/usr/local/mysql/doc \
      -DINSTALL_INCLUDEDIR=/usr/local/mysql/include \
      -DINSTALL_INFODIR=/usr/local/mysql/share/info \
      -DINSTALL_MYSQLSHAREDIR=/usr/local/mysql/share/mysql \
      -DINSTALL_MYSQLTESTDIR=/usr/local/mysql/mysql-test \
      -DINSTALL_PLUGINDIR=/usr/local/mysql/lib/plugin \
      -DINSTALL_SBINDIR=/usr/local/mysql/bin \
      -DINSTALL_SCRIPTDIR=/usr/local/mysql/bin \
      -DINSTALL_SHAREDIR=/usr/local/mysql/share \
      -DINSTALL_SQLBENCHDIR=/usr/local/mysql/sql-bench \
      -DINSTALL_SUPPORTFILESDIR=/usr/local/mysql/share \
      -DINSTALL_LIBDIR=/usr/local/mysql/lib \
      -DINSTALL_MYSQLCONFDIR=/etc/mysql \
      ..
    
  4. 编译源代码

    make -j$(nproc) #核心对应进程数目,有几个核心就跑几个进程
    
  5. 安装 MySQL

     make install
    

初始化 MySQL 数据库

1.创建数据目录

   useradd -s /sbin/nologin -M mysql
    mkdir -p /usr/local/mysql/data
    chown -R $(whoami):$(whoami) /usr/local/mysql/data
    #chown mysql.mysql /data/mysql/   #一般而言是这样

$whoani=>mysql

2.修改环境变量

[root@node10 ~]# vim ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin
[root@node10 ~]# source ~/.bash_profile

3.修改配置文件

[root@node10 my.cnf.d]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql #指定数据目录
socket=/data/mysql/mysql.sock #指定套接字
symbolic-links=0 #数据只能存放到数据目录中,禁止链接到数据目录

4.初始化数据库

 cd /usr/local/mysql/bin
mysqld --initialize --user=mysql
 /etc/init.d/mysqld start
 chkconfig mysqld on

5.数据库安全初始化

mysql_secure_installation

Securing the MySQL server deployment.
Enter password for user root: #输入当前密码
在mysql初始化阶段会生成一个临时密码,这个临时密码就是安全初始化的时候使用的当前密码
The existing password for the user account root has expired. Please set a new
password.
New password: #输入新密码
Re-enter new password: #重复密码
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: no #是否启用密码插件
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : no#是否要重置密码
… skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No): y
Dropping test database…
Success.
Removing privileges on test database…
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

6.创建启动脚本

[root@node10 ~]# dnf install initscripts-10.11.6-1.el9.x86_64 -y
[root@node10 ~]# cd /usr/local/mysql/support-files/
[root@node10 support-files]# cp mysql.server /etc/init.d/mysqld

7.登录 MySQL

 ./mysql -u root -p

http://www.kler.cn/news/283003.html

相关文章:

  • “重启就能解决一切问题”,iPhone重启方法大揭秘
  • 解决:无法从域控制器读取配置信息
  • 2024.8.29 C++
  • C#面:ASP.NET MVC 中还有哪些注释属性用来验证?
  • RKNPU2从入门到实践 ---- 【8】借助 RKNN Toolkit lite2 在RK3588开发板上部署RKNN模型
  • 设计模式--装饰器模式
  • 理解torch.argmax() ,我是错误的
  • 融资和融券分别是什么意思,融资融券开通后能融到多少资金?
  • Datawhale X 李宏毅苹果书 AI夏令营_深度学习基础学习心得Task2.2
  • Java 入门指南:Java NIO —— Selector(选择器)
  • 【hot100篇-python刷题记录】【搜索二维矩阵】
  • 分布式锁的实现:ZooKeeper 的解决方案
  • hive数据迁移
  • 低代码革命:JNPF平台如何简化企业应用开发
  • Linux 中的中断响应机制
  • TCP keepalive和HTTP keepalive区别
  • SCP拷贝失败解决办法
  • 基于单片机的指纹识别考勤系统设计
  • Web应用服务器Tomcat
  • 基于STM32开发的智能家居温度控制系统
  • Linux下的使用字符设备驱动框架编写ADC驱动 ——MQ-4传感器
  • 我在高职教STM32——ADC电压采集与光敏电阻(2)
  • rnn-手动实现
  • 区块链入门
  • Element Plus上传图片前,对图片进行压缩
  • 基于asp.net的webform图书管理系统附源码
  • django 中 csrf 的实现机制
  • CVE-2024-26229 漏洞复现分析
  • 详解PASCAL VOC数据集及基于Python和PyTorch的下载、解析及可视化【目标检测+类别分割】
  • 回归预测|基于北方苍鹰优化最小二乘支持向量机的数据预测Matlab程序NGO-LSSVM 多特征输入单输出 含基础程序