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

ubuntu 22.04安装mysql5.7

环境
Os:ubuntu 22.04 desktop桌面版
mysql:mysql-5.7.42-linux-glibc2.12

 

查看操作系统信息

root@db:~# ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3) 2.35
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
root@db:~# uname -a
Linux db 6.8.0-79-generic #79~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 15 16:54:53 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
root@db:~# more /etc/os-release 
PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 (Jammy Jellyfish)"
VERSION_CODENAME=jammy
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=jammy

 

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

2.创建mysql用户和用户组(系统已经自动创建了的话,不需要创建)
root@db:/soft# groupadd mysql
root@db:/soft# useradd mysql -s /sbin/nologin -M -g mysql


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


3.下载解压二进制文件,解压,进入解压出来的文件
root@db:/soft# cd /soft
root@db:/soft# tar -xvf mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
root@db:/soft# mv mysql-5.7.42-linux-glibc2.12-x86_64 /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,配置文件内容如下

root@db:/home/middle/mysql57/conf# more 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.初始化数据库
cd /home/middle/mysql57/bin
root@db:/home/middle/mysql57/bin# ./mysqld --initialize --lower-case-table-names=1 --user=mysql --basedir=/home/middle/mysql57 --datadir=/home/middle/mysql57/data
2025-09-15T09:15:06.515692Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-09-15T09:15:06.706209Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-15T09:15:06.742841Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-15T09:15:06.804769Z 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: 788dd480-9214-11f0-98b6-0800273de355.
2025-09-15T09:15:06.807860Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-15T09:15:07.142264Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-15T09:15:07.142442Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-15T09:15:07.142990Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-15T09:15:07.195804Z 1 [Note] A temporary password is generated for root@localhost: lS3lwiolOj=N

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并修改密码
root@db:/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@db:/home/middle# find / -name libncurses.so*

/snap/core20/1405/usr/lib/x86_64-linux-gnu/libncurses.so.6
/snap/core20/1405/usr/lib/x86_64-linux-gnu/libncurses.so.6.2
/usr/lib/x86_64-linux-gnu/libncurses.so.6.3
/usr/lib/x86_64-linux-gnu/libncurses.so.6
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied

root@db:/home/middle# find / -name libtinfo.so*
/snap/core20/1405/usr/lib/x86_64-linux-gnu/libtinfo.so.6
/snap/core20/1405/usr/lib/x86_64-linux-gnu/libtinfo.so.6.2
/usr/lib/x86_64-linux-gnu/libtinfo.so.6
/usr/lib/x86_64-linux-gnu/libtinfo.so.6.3
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied

建立软连接
ln -s /usr/lib/x86_64-linux-gnu/libncurses.so.6.3 /usr/lib/x86_64-linux-gnu/libncurses.so.5
ln -s /usr/lib/x86_64-linux-gnu/libtinfo.so.6.3 /usr/lib/x86_64-linux-gnu/libtinfo.so.5


mysql> select version();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

修改密码
mysql> set password=password('mysql');


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

创建数据库
mysql> create database db_test;
Query OK, 1 row affected (0.02 sec)

创建开发用户
grant all on db_test.* to 'hxl'@'%' identified by 'mysql';


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=4831

相关文章:

  • Docker如何获取镜像
  • 2025 ICPC 网络赛2 E
  • 偏移寻址
  • 金融业-数字化转型大赛-网络安全赛道部分wp
  • Mysql查找含字符串表字段
  • MySQL注意事项与规范 - 实践
  • 真正的元推理,不需要人类的认可,恰恰是人类追求元推理,只有元推理才能彻底解放人类
  • 西电微机原理-第三章 Intel处理器指令系统及汇编语言(5)
  • 西电微机原理-第五章 存储技术
  • 西电微机原理-第七章 常用接口器件
  • CF1264D1 Beautiful Bracket Sequence (easy version)
  • 西电微机原理-第六章 输入输出技术
  • 【FAQ】应用A如何使用应用B内的文件?
  • OpenStack Cinder 创建卷
  • 西电微机原理-第二章 Intel单核处理器
  • 二叉树的迭代遍历(非递归)
  • 记录---用好了 defineProps 才叫会用 Vue3,90% 的写法都错了
  • 今日流水账-2025年9月15日
  • c#给原文件重命名
  • tcpdump常用随笔
  • 2025年HR经理必备:10款高效人力资源管理软件推荐
  • GAS中GA变量数据的同步
  • 提升员工绩效的5大人才管理软件评测与分析
  • 【触想智能】工业显示屏与普通显示屏的八大区别以及应用领域分析
  • LLaVA- Improved Baselines with Visual Instruction Tuning - jack
  • 042-WEB 攻防:PHP 应用 MYSQL 架构 SQL 注入 跨库查询 文件读写 权限操作
  • Dsu On Tree 笔记
  • 西电微机原理-第一章 序论:微型计算机概述
  • Liunx 硬盘扩容
  • 船舶航向控制算法