OpenEuler下面解压安装
tar包解压安装
公司可能有固定版本的要求,或者有特定的插件需要安装在mysql里面,因此,从公司资源库中下载固定版本的安装包应该是比较合理的。
下载
可以从官方网站下载,也可以从下面给出的地址下载
MYSQL 内部下载
下载完,加压文件到 /opt
tar xfz mysql-5.7.44-el7-x86_64.tar.gz -C /opt
[root@localhost opt]cd /opt/mysql-5.7.44-el7-x86_64
[root@localhost bin]# ./mysqld --initialize --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/var/lib/mysql
2025-12-20T02:22:02.620678Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-12-20T02:22:02.620802Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2025-12-20T02:22:02.799993Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-12-20T02:22:02.839123Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-12-20T02:22:02.900844Z 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: abda35bf-dd4a-11f0-bb6a-bc2411dd4da2.
2025-12-20T02:22:02.906073Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-12-20T02:22:04.079016Z 0 [Warning]
2025-12-20T02:22:04.079051Z 0 [Warning]
2025-12-20T02:22:04.081626Z 0 [Warning] CA certificate ca.pem is self signed.
2025-12-20T02:22:04.696307Z 1 [Note] A temporary password is generated for root@localhost: Jr%NlRQns53*
记得最后一行有初始化密码,必须保留记住Jr%NlRQns53*
设置配置文件
# 创建配置文件
sudo tee /etc/my.cnf << 'EOF'
[mysqld]
basedir=
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
port=3306
user=mysql
# 字符集设置
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
# 其他配置
max_connections=1000
innodb_buffer_pool_size=128M
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
default-character-set=utf8mb4
socket=/tmp/mysql.sock
EOF
# 创建必要的目录
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo touch /var/log/mysqld.log
sudo chown mysql:mysql /var/log/mysqld.logopenEuler下缺少ncurses库文件,需要安装
注意,centos7下面是不需要安装的。
sudo dnf install -y ncurses-compat-libs安装服务文件
sudo tee /usr/lib/systemd/system/mysqld.service << 'EOF'
[Unit]
Description=MySQL Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/var/run/mysqld/mysqld.pid
# 禁用MySQL的自动关闭
PermissionsStartOnly=true
TimeoutSec=0
# 主进程启动命令
ExecStart=/opt/mysql-5.7.44-el7-x86_64/bin/mysqld --daemonize \
--basedir=/usr/local/mysql \
--datadir=/var/lib/mysql \
--pid-file=/var/run/mysqld/mysqld.pid
# 使用这个ExecStop来正确停止MySQL
ExecStop=//opt/mysql-5.7.44-el7-x86_64/bin/mysqladmin -u root -p shutdown
# 如果使用mysqladmin失败,则使用这个
ExecStop=/bin/kill -s TERM $MAINPID
# 重启配置
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
[Install]
WantedBy=multi-user.target
EOF开机启动 mysqld
systemctl enable mysqld --now
path路径的重新设置
tee /etc/profile.d/mysql.sh <<'EOF'
export PATH=/opt/mysql-5.7.44-el7-x86_64/bin/:$PATH
EOF
# 执行
. /etc/profilemysql登陆
mysql -uroot -p
密码是你初始化sh的密码
作者:严锋 创建时间:2025-12-20 10:01
最后编辑:严锋 更新时间:2025-12-25 10:39
最后编辑:严锋 更新时间:2025-12-25 10:39