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

ubuntu24.04安装mysql5.7.42

 

环境
Os:ubuntu 24.04 desktop桌面版
mysql:5.7.42

说明:

a.ubuntu24下安装mysql 5.7 使用的依赖库 需要创建软连接指向新的依赖库.

 

 

查看操作系统信息

root@hxl-VirtualBox:/# uname -a
Linux hxl-VirtualBox 6.14.0-29-generic #29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Aug 14 16:52:50 UTC 2 x86_64 x86_64 x86_64 GNU/Linuxroot@hxl-VirtualBox:/# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.3 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

 

1.介质准备
mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
该介质可以从官网上进行下载

2.创建mysql用户和用户组(取消,系统已经自动创建了)
说明:V10已经存在mysql组和mysql用户,V11需要安装如下创建
root@hxl-VirtualBox:/soft# groupadd mysql
root@hxl-VirtualBox:/soft# useradd mysql -s /sbin/nologin -M -g mysql


3.创建安装目录
[root@localhost soft]# mkdir -p /home/middle


3.下载解压二进制文件,解压,进入解压出来的文件
root@hxl-VirtualBox:/soft# cd /soft
root@hxl-VirtualBox:/soft# tar -xvf mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
root@hxl-VirtualBox:/soft# mv mysql-5.7.42-linux-glibc2.12-x86_64 /home/middle/mysql57
root@hxl-VirtualBox:/soft# cd /home/middle/mysql57

4.在mysql主目录下建立相应的目录
data目录存放数据文件,conf目录存放配置文件
[root@localhost mysql5733]#cd /home/middle/mysql57
[root@localhost mysql5733]#mkdir data ##数据文件目录
[root@localhost mysql5733]#mkdir conf ## 配置文件目录
[root@localhost mysql5733]#mkdir -p mysqllog/relaylog ##主从环境relaylog
[root@localhost mysql5733]#mkdir -p mysqllog/logfile ##错误日志文件
[root@localhost mysql5733]#mkdir -p mysqllog/binlog ##binlog文件
[root@localhost mysql5733]#mkdir -p secure_file ##secure_file_priv参数指定路

 

5.在conf目录下创建配置文件my.cnf,配置文件内容如下

[mysqld]
port=13306
server-id=1
basedir=/home/middle/mysql57
datadir=/home/middle/mysql57/data
max_connections = 5000
character_set_server=utf8mb4
collation-server=utf8mb4_general_ci
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'
interactive_timeout=86400
wait_timeout=86400
skip-external-locking
key_buffer_size= 128M
max_allowed_packet=32M
query_cache_size=32M
read_buffer_size=2M
sort_buffer_size=1M
join_buffer_size= 128M
innodb_file_per_table= 1
innodb_open_files= 5000
innodb_buffer_pool_size= 4G
innodb_write_io_threads= 16
innodb_read_io_threads= 16
innodb_thread_concurrency = 0
innodb_purge_threads= 1
innodb_flush_log_at_trx_commit= 2
innodb_log_buffer_size=16M
innodb_log_file_size=512M
innodb_log_files_in_group= 5
innodb_max_dirty_pages_pct= 90
innodb_lock_wait_timeout= 120
bulk_insert_buffer_size= 64M
myisam_sort_buffer_size=64M
myisam_max_sort_file_size= 10G
log_bin_trust_function_creators=1
event_scheduler=1
max_binlog_size=100M
binlog_format=row
log-bin=/home/middle/mysql57/mysqllog/binlog/binlog.bin
slow_query_log=on
slow_query_log_file=/home/middle/mysql57/mysqllog/logfile/slow-query.log
long_query_time=1
log_queries_not_using_indexes=on
log-error=/home/middle/mysql57/mysqllog/logfile/mysql-err.log
binlog_cache_size=4MB
skip-host-cache
skip-name-resolve
expire_logs_days=15
skip-slave-start
relay-log-index=/home/middle/mysql57/mysqllog/relaylog/slave-relay-bin.index
relay-log=/home/middle/mysql57/mysqllog/relaylog/relaylog-binlog
replicate-ignore-db=information_schema,performance_schema,sys
slave_net_timeout=60
language=/home/middle/mysql57/share/english
early-plugin-load=""
explicit_defaults_for_timestamp=true
log_slave_updates=1
gtid_mode=ON
enforce_gtid_consistency = ON
lower_case_table_names=1
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
secure_file_priv=/home/middle/mysql57/secure_file[client]
port = 13306
default-character-set = utf8mb4[mysqldump]
quick
max_allowed_packet = 32M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

 

6.修改mysql目录权限
[root@localhost opt]#cd /home/middle
[root@localhost opt]# chown -R mysql:mysql ./mysql57

 

7.初始化数据库

root@localhost:/home/middle/mysql57/bin# ./mysqld --initialize --user=mysql --basedir=/home/middle/mysql57 --datadir=/home/middle/mysql57/data --lc_messages_dir=/home/middle/mysql57/share --lc_messages=en_US
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解决办法:
apt install numactl libaio1t64 -y

 

 

创建软连接
cd /usr/lib/x86_64-linux-gnu/
ln -s libaio.so.1t64.0.2 libaio.so.1
ln -s libncursesw.so.6.4 libncurses.so.6 ##好像这句不用执行,已经存在了软连接

root@hxl-VirtualBox:/home/middle/mysql57/bin# ./mysqld --initialize --user=mysql --basedir=/home/middle/mysql57 --datadir=/home/middle/mysql57/data --lc_messages_dir=/home/middle/mysql57/share --lc_messages=en_US
2025-09-11T08:09:09.743425Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-09-11T08:09:10.794128Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-11T08:09:11.082866Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-11T08:09:11.148371Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 992590ba-8ee6-11f0-b73f-080027277efd.
2025-09-11T08:09:11.153240Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-11T08:09:11.437028Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-11T08:09:11.437252Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-11T08:09:11.438540Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-11T08:09:11.542552Z 1 [Note] A temporary password is generated for root@localhost: gzO9n;3yU.DP

 

8.启动
[root@localhost opt]#echo>/home/middle/mysql57/mysqllog/logfile/mysql-err.log
[root@localhost opt]#cd /home/middle
[root@localhost opt]#chown -R mysql:mysql ./mysql57

[root@localhost middle]# /home/middle/mysql57/bin/mysqld_safe --defaults-file=/home/middle/mysql57/conf/my.cnf --user=mysql &

 

9.登陆mysql并修改密码
[mysql@localhost bin]$ /home/middle/mysql57/bin/mysql -h localhost -uroot -P13306 -p
Enter password:

报错误:
root@hxl-VirtualBox:/home/middle# /home/middle/mysql57/bin/mysql -h localhost -uroot -P13306 -p
/home/middle/mysql57/bin/mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

解决办法:
root@localhost:~# find / -name libncurses.so*
/usr/lib/x86_64-linux-gnu/libncurses.so.6
/usr/lib/x86_64-linux-gnu/libncurses.so.6.4
/snap/core22/2111/usr/lib/x86_64-linux-gnu/libncurses.so.6
/snap/core22/2111/usr/lib/x86_64-linux-gnu/libncurses.so.6.3
/snap/core22/2045/usr/lib/x86_64-linux-gnu/libncurses.so.6
/snap/core22/2045/usr/lib/x86_64-linux-gnu/libncurses.so.6.3
find: ‘/run/user/1000/gvfs’: Permission denied
find: ‘/run/user/1000/doc’: Permission deniedroot@localhost:/soft# find / -name libtinfo.so*
/usr/lib/x86_64-linux-gnu/libtinfo.so.6
/usr/lib/x86_64-linux-gnu/libtinfo.so.5
/usr/lib/x86_64-linux-gnu/libtinfo.so.6.4
/snap/core22/2111/usr/lib/x86_64-linux-gnu/libtinfo.so.6
/snap/core22/2111/usr/lib/x86_64-linux-gnu/libtinfo.so.6.3
/snap/core22/2045/usr/lib/x86_64-linux-gnu/libtinfo.so.6
/snap/core22/2045/usr/lib/x86_64-linux-gnu/libtinfo.so.6.3
find: ‘/run/user/1000/gvfs’: Permission denied
find: ‘/run/user/1000/doc’: Permission denied
建立软连接 ln
-s /usr/lib/x86_64-linux-gnu/libncurses.so.6.4 /usr/lib/x86_64-linux-gnu/libncurses.so.5 ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6 /usr/lib/x86_64-linux-gnu/libtinfo.so.5

 

修改密码,密码复杂度建议18位数
mysql> set password=password('mysql');


删除系统自带用户(看实际情况需要)

mysql> delete from mysql.user where user='mysql.session';
Query OK, 1 row affected (0.06 sec)

 

mysql> delete from mysql.user where user='mysql.sys';
Query OK, 1 row affected (0.06 sec)

 

10.重启
停掉
su - root
/home/middle/mysql57/bin/mysqladmin -h localhost -uroot -P13306 -pmysql shutdown

启动
/home/middle/mysql57/bin/mysqld_safe --defaults-file=/home/middle/mysql57/conf/my.cnf --user=mysql &


11.正常登录
/home/middle/mysql57/bin/mysql -h localhost -uroot -P13306 -p


12.停掉数据库
方便后面使用系统命令启动
/home/middle/mysql57/bin/mysqladmin -h localhost -uroot -P13306 -pmysql shutdown

 

13.设置开启自启动

设置开机自启动
在/etc/systemd/system目录下创建 mysql.service 文件
root下操作
vi /etc/systemd/system/mysql.service

[Unit]
Description=mysql
[Service]
User=mysql
LimitNOFILE=100000
LimitNPROC=100000
ExecStart=/home/middle/mysql57/bin/mysqld_safe --defaults-file=/home/middle/mysql57/conf/my.cnf
[Install]
WantedBy=multi-user.target

 

注意如下两个参数不能设置太小,否则mysql会不停重启动

LimitNOFILE=100000
LimitNPROC=100000


设置开机自启
systemctl enable mysql
systemctl daemon-reload

 

尝试启动
systemctl start mysql
systemctl status mysql

systemctl stop mysql
systemctl status mysql

可以的话进行系统reboot,看是否会自动启动

 

##########################安装xtrabackup##############################
准备安装介质
percona-xtrabackup-2.4.28-Linux-x86_64.glibc2.17.tar.gz

cd /soft
tar -xvf percona-xtrabackup-2.4.28-Linux-x86_64.glibc2.17.tar.gz
mv percona-xtrabackup-2.4.28-Linux-x86_64.glibc2.17 /opt/xtrabackup-2.4.28


备份
/opt/xtrabackup-2.4.28/bin/innobackupex --defaults-file=/home/middle/mysql57/conf/my.cnf --user=root --password=mysql --socket=/tmp/mysql.sock --stream=tar /tmp|gzip >/tmp/xtrabackup_20250912.tar.gz

 

 

http://www.wxhsa.cn/company.asp?id=1823

相关文章:

  • 易基因:Cell封面:中国科学家杨学勇/黄三文m6A-seq等揭示同义突变通过表观转录调控机制决定生物性状|顶刊突破
  • 一文看懂Deepspeed:用ZeRO训练大模型原理解析及参数含义解释
  • AC-DC整流器双闭环控制MATLAB/Simulink仿真
  • 新娘化妆 造型 美甲 护肤 资料合集
  • rabbitMQ-基础day1 - a
  • 实用指南:Nginx反向代理与负载均衡部署
  • C# Avalonia 13- MoreDrawing - BlurEffects
  • 【IEEE出版】第三届算法、图像处理与机器视觉国际学术会议(AIPMV2025)
  • C++ - 了解STL的数据容器
  • 收费详情
  • bluetoothctl UUIDs
  • ANOLIS8安装配置ldap账号登录
  • 实用指南:小程序非主页面的数据动作关联主页面的数据刷新操作
  • 【光照】[光照模型]是什么?以UnityURP为例
  • 从知识管理困境到高效协同:Gitee Wiki如何重塑研发团队的知识体系
  • PHP数组去重和集合有什么关系
  • kkFileView4.4.0 安装与使用
  • ubuntu22挂载windows server2019的共享文件夹
  • PHP数组去重适用于哪些场景
  • 下载视频
  • 常用Linux配置
  • m1max可以装windows系统很卡吗
  • 1 | 移动语义:浅拷贝,深拷贝和引用拷贝,左值和右值
  • macbook air和windows系统区别
  • Gitee:国产代码托管的领军者,助力企业应对CODING停服挑战
  • 锂电池外围均衡电路仿真
  • Wireshark 学习笔记(一)
  • ELF 文件结构与加载流程介绍
  • 灵码产品演示:Maven 示例工程生成
  • NocoBase 本周更新汇总:优化及缺陷修复