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

二进制/源码编译安装mysql 8.0

二进制方式:

1.下载或上传安装包至设备:

2.创建组与用户:

[root@openEuler-1 ~]# groupadd mysql
[root@openEuler-1 ~]# useradd -r -g  mysql -s /bin/false mysql

3.解压安装包:

tar xf mysql-8.0.36-linux-glibc2.12-x86_64.tar.xz -C /usr/local

4.建立软链接:

 ln -sv /usr/local/mysql-8.0.36-linux-glibc2.12-x86_64/ /usr/local/mysql

5.初始化:

[root@openEuler-1 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
2025-01-15T15:01:42.254967Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.36) initializing of server in progress as process 1935
2025-01-15T15:01:42.260421Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-01-15T15:01:42.971402Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-01-15T15:01:44.318709Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >HYAHNuRd4+f        (初始密码)

6.编辑配置文件:

[root@openEuler-1 ~]# vim /etc/my.cnf
 

basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid

7.给予软件目录权限:

[root@openEuler-1 ~]# chown -R mysql.mysql /usr/local/mysql/*

8.拷贝服务脚本:

[root@openEuler-1 ~]# cd /usr/local/mysql/
[root@openEuler-1 mysql]# ls
bin  data  docs  include  lib  LICENSE  man  README  share  support-files
[root@openEuler-1 mysql]# cd support-files/
[root@openEuler-1 support-files]# ls
mysqld_multi.server  mysql-log-rotate  mysql.server
[root@openEuler-1 support-files]# cp mysql.server /etc/init.d/mysqld

9.将服务脚本添加为系统服务:

[root@openEuler-1 support-files]# chkconfig --add mysqld
[root@openEuler-1 support-files]# ll /etc/rc.d/rc3.d/
total 0
lrwxrwxrwx 1 root root 16 Jan 15 23:30 S64mysqld -> ../init.d/mysqld

10.将服务脚本设置为开机自启动:

[root@openEuler-1 support-files]# chkconfig mysqld on
[root@openEuler-1 support-files]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

11.启动服务:

[root@openEuler-1 ~]# systemctl start mysql
[root@openEuler-1 ~]# systemctl status mysql
● mysqld.service - LSB: start and stop MySQL
     Loaded: loaded (/etc/rc.d/init.d/mysqld; generated)
     Active: active (running) since Wed 2025-01-15 23:49:43 CST; 32s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 2450 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=>
      Tasks: 39 (limit: 8932)
     Memory: 462.6M
     CGroup: /system.slice/mysqld.service
             ├─ 2463 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/usr/l>
             └─ 2621 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ -->

Jan 15 23:49:41 openEuler-1 systemd[1]: Starting LSB: start and stop MySQL...
Jan 15 23:49:41 openEuler-1 mysqld[2450]: Starting MySQL.
Jan 15 23:49:41 openEuler-1 mysqld[2463]: Logging to '/usr/local/mysql/data/mys>
Jan 15 23:49:43 openEuler-1 mysqld[2450]: . SUCCESS!
Jan 15 23:49:43 openEuler-1 systemd[1]: Started LSB: start and stop MySQL.

12.安装依赖:

[root@openEuler-1 ~]# yum install ncurses-compat-libs

13.使用绝对路径登录,并修改密码:

[root@openEuler-1 ~]# /usr/local/mysql/bin/mysql -uroot -p
Enter password: (>HYAHNuRd4+f)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.36

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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
    -> ;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER root@localhost  identified by '123';
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql>  show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
 

14.配置环境变量:

[root@openEuler-1 ~]# vim /etc/profile.d/mysql.sh

#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin/

[root@openEuler-1 ~]# source /etc/profile.d/mysql.sh  #使立即生效,加载到 当前
 

验证:

[root@openEuler-1 ~]# mysql -uroot -p123
mysql: [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 9
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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>
 

源码编译方式:

 服务配置方法2:
注意:两种不要同时配置

服务配置
vi /usr/lib/systemd/system/mysqld.service

##加入以下内容即可
[Unit]
Description=Mysql server
After=network.target
 
[Install]
WantedBy=multi-user.target
 
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID  
ExecStop=/bin/kill -s QUIT $MAINPID 
 
KillMode=process
LimitNOFILE=65535
Restart=on-failure
RestartSec=10
RestartPreventExitStatus=1
PrivateTmp=false

加载设置
  systemctl daemon-reload
启动服务
 

http://www.lryc.cn/news/522652.html

相关文章:

  • 2025-1-15-十大经典排序算法 C++与python
  • 头盔识别技术
  • DeepSeek-v3在训练和推理方面的优化
  • 将 AzureBlob 的日志通过 Azure Event Hubs 发给 Elasticsearch(3 纯python的经济方案)
  • 1️⃣Java中的集合体系学习汇总(List/Map/Set 详解)
  • 闪豆多平台视频批量下载器
  • 深入解析:如何用Java爬取淘宝分类详情接口(cat_get)
  • 语音识别的预训练模型
  • element-ui制作多颜色选择器
  • JVM体系结构
  • wandb使用遇到的一些问题
  • Java中的继承
  • Cadence笔记--原理图导入PCB
  • 从AI生成内容到虚拟现实:娱乐体验的新边界
  • 【Linux】gdb_进程概念
  • 安全类脚本:拒绝ssh暴力破解
  • Android15源码编译问题处理
  • 图解Git——分布式Git《Pro Git》
  • Linux内核编程(二十一)USB应用及驱动开发
  • 什么是数据仓库?
  • 计算机网络 (48)P2P应用
  • SK海力士(SK Hynix)是全球领先的半导体制造商之一,其在无锡的工厂主要生产DRAM和NAND闪存等存储器产品。
  • FunASR 在Linux/Unix 平台编译
  • git操作(Windows中GitHub)
  • 物联网网关Web服务器--Boa服务器移植与测试
  • vue3学习日记8 - 一级分类
  • 前端实习第二个月小结
  • 深入了解卷积神经网络(CNN):图像处理与深度学习的革命性技术
  • b站视频(网页加客户端)+本地视频 生成回链
  • 3.数据库系统