相关资料
操作系统: Ubuntu 24.04
数据库下载地址: https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
部署
# 安装必要的依赖
apt -y install numactl libaio1t64 -y
ln -sv /usr/lib/x86_64-linux-gnu/libtinfo.so.6.4 /usr/lib/x86_64-linux-gnu/libtinfo.so.5
ln -sv /usr/lib/x86_64-linux-gnu/libaio.so.1t64.0.2 /usr/lib/x86_64-linux-gnu/libaio.so.1
# 添加用户和用户组
groupadd -r mysql
useradd -M -g mysql -r -s /bin/false -c "MySQL Server" mysql
# 下载和解压 mysql 二进制安装包
mkdir /data/software -p
cd /data/software
wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
cp -rf mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql8_3306
# 创建数据和日志目录
cd /data/
mkdir mysql8_3306/{data,log,log-bin} -p
touch mysql8_3306/log/mysql-err.log
chown -R mysql:mysql /data/mysql8_3306
# 创建配置
cat >> /usr/local/mysql8_3306/my.cnf << EOF
[mysqld]
port=3306
log-error=/data/mysql8_3306/log/mysql-err.log
basedir=/usr/local/mysql8_3306
datadir=/data/mysql8_3306/data
socket=/data/mysql8_3306/mysql.sock
server-id=1
log-bin=/data/mysql8_3306/log-bin/mysql-bin
character-set-server=utf8mb4
default-storage-engine=INNODB
user=mysql
lower_case_table_names=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLE
max_connect_errors=2000
max_connections=1500
default-authentication-plugin=mysql_native_password
[client]
socket=/data/mysql8_3306/mysql.sock
default-character-set=utf8mb4
EOF
# 初始化数据库
cd /usr/local/mysql8_3306
./bin/mysqld --defaults-file=/usr/local/mysql8_3306/my.cnf --initialize --console --user=mysql
# 创建 systemctl 配置
cat >/etc/systemd/system/mysqld8_3306.service <<EOF
[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
ExecStart=/usr/local/mysql8_3306/bin/mysqld --defaults-file=/usr/local/mysql8_3306/my.cnf
LimitNOFILE = 5000
EOF
# 启动数据库和设置开机启动
systemctl start mysqld8_3306
systemctl enable mysqld8_3306
# 获取数据库初始密码
grep "password" /data/mysql8_3306/log/mysql-err.log
# 使用初始密码登录数据库
cd /usr/local/mysql8_3306
./bin/mysql --socket=/data/mysql8_3306/mysql.sock -uroot -p
# 修改密码
alter user root@localhost identified by "KLVCHEN123456";
flush privileges;
use mysql;
update user set host = '%' where user = 'root';
flush privileges;
ALTER USER 'root'@'%' PASSWORD EXPIRE NEVER;
flush privileges;
标签:8.0,20,x86,24.04,mysql,64,linux,3306
From: https://www.cnblogs.com/klvchen/p/18534590