Ubuntu2204二进制安装MySQL及包安装
MySQL二进制安装及包安装
apt直接安装
链接:https://blog.csdn.net/fenglailea/article/details/127265066
国内源
源
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverses
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
#########详细配置链接:https://blog.csdn.net/fenglailea/article/details/127265066
二进制安装8.0
ubuntu2204安装MySQL8.0版本
支持链接:https://blog.csdn.net/qq18587599905/article/details/123334577
下载版本:https://downloads.mysql.com/archives/community/
1.解压(里面包含文档文件)
tar -xf mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar
2.选择版本,再次解压(选择MySQL应用文件、最大的)
tar -xf mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz -C /apps/
3.我这里为了方便把名字改了
mv mysql-8.0.28-linux-glibc2.17-x86_64-minimal mysql
4. 创建用户组
groupdel mysql #删除组
groupadd mysql #添加组
5.创建用户
userdel mysql #删除用户
useradd -r -g mysql -s /bin/false mysql #添加用户 -g mysql 是指定用户组 -s /bin/false 是指定用户所使用的shell 最后mysql是用户名称
6. 指定mysql文件夹为mysql用户所有
chown mysql ./mysql -R
7.在data目录下创建mysql相关文件夹文件夹
mkdir /apps/mysql
mkdir /apps/mysql/logs
mkdir /apps/mysql/conf
mkdir /apps/mysql/data
8.安装相关依赖
apt-get install libaio1 libaio-dev -y
apt-get install libncurses5-dev -y
编写my.cnf文件
##########################################注意:只是模板文件、生产环境还是按需修改
vim /apps/mysql/conf/my.cnf
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[mysqld]
### 忘记密码时使用
###skip-grant-tables
skip-name-resolve
user=mysql
ngram_token_size=2
server-id=1
default_password_lifetime=0
port=3306
### 设置安装目录
basedir=/apps/mysql
### 数据存放目录
datadir=/apps/mysql/data
log-error=/apps/mysql/logs/err.log
log-bin=/apps/mysql/logs/binlog
### 允许最大连接数
max_connections=1000
### 服务端默认使用的字符集
character-set-server=utf8mb4
### 创建新表时默认的存储引擎
default-storage-engine=INNODB
### 不区分大小写
lower_case_table_names=1
### 认证方式
default_authentication_plugin=mysql_native_password
max_allowed_packet=500M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
wait_timeout=28800
interactive_timeout=28800
max_connect_errors=100
max_user_connections=0
###日志文件大小
max_binlog_size=100M
安装初始化启动
###指定配置文件安装(类似初始化应用:使用指定的配置文件初始化 MySQL 数据目录)
cd /apps/mysql/bin/
./mysqld --defaults-file=/apps/mysql/conf/my.cnf --initialize
###指定配置文件启动(手动启动MySQL)
./mysqld --defaults-file=/apps/mysql/conf/my.cnf &
创建文件 mysql.service
vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
# Have mysqld write its state to the systemd notify socket
Type=notify
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Start main service
ExecStart=/apps/mysql/bin/mysqld --defaults-file=/apps/mysql/conf/my.cnf $MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE=10000
Restart=on-failure
RestartPreventExitStatus=1
# Set environment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
启动
systemctl daemon-reload
systemctl start mysql ###启动(先把上面手动启动的kill掉)
systemctl stop mysql ###停止
systemctl restart mysql ###重启
systemctl enable mysql ###开机自启
添加环境变量
vim .bashrc
export PATH="$PATH:/apps/mysql/bin"
跳过认证
晚上10:30执行(业务停止后执行、这一步必须重启MySQL加载)
vim /etc/my.conf
[mysqld]
skip-grant-tables
重启
systemctl restart mysqld
连接直接上去
mysql
刷新权限(注意:一定刷新权限、否则啥也执行不了)
FLUSH PRIVILEGES;
下面开始创建用户操作
查看认证插件
SELECT user, plugin FROM mysql.user;
根据认证插件创建用户并且授权
CREATE USER 'root'@'%' IDENTIFIED BY 'AAbb-123.';
CREATE USER 'root'@'%' IDENTIFIED BY 'AAbb-123.';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH PRIVILEGES;
最后连接使用
mysql -uroot -pAAbb-123. -h127.0.0.1

浙公网安备 33010602011771号