下载并解压
[root@openeuler ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
[root@openeuler ~]# tar zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
更改路径
[root@openeuler ~]# mv mysql-8.0.11-linux-glibc2.12-x86_64 /usr/local/mysql
[root@openeuler ~]# ls /usr/local/mysql
bin  docs  include  lib  LICENSE  man  README  share  support-files
创建数据存放目录和用户,并修改目录权限
[root@openeuler ~]# mkdir -p /usr/local/mysql/data
[root@openeuler ~]# groupadd mysql && useradd -r -g mysql mysql
[root@openeuler ~]# chown -R mysql:mysql /usr/local/mysql/
初始化数据库
[root@openeuler ~]# cd /usr/local/mysql
[root@openeuler mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
2025-01-06T02:40:17.844382Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) initializing of server in progress as process 53943
2025-01-06T02:40:19.301346Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: (wat#<IyB2;j
2025-01-06T02:40:20.094478Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) initializing of server has completed
# 记录密码:(wat#<IyB2;j
配置环境变量
[root@openeuler mysql]# vim /etc/profile
# 增加以下两行
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
[root@openeuler mysql]# source /etc/profile  
修改配置文件my.cnf
[root@openeuler mysql]# vim /etc/my.cnf 
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/mysql.sock
character-set-server=utf8
port = 3306
bind-address = 0.0.0.0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[client]
socket = /usr/local/mysql/mysql.sock
default-character-set=utf8
配置MySQL服务
[root@openeuler mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@openeuler mysql]# chmod +x /etc/init.d/mysqld
[root@openeuler mysql]# chkconfig --add mysqld
配置用Systemctl来管理Mysql
[root@openeuler mysql]# 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
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@openeuler mysql]# systemctl stop firewalld
[root@openeuler mysql]# setenforce 0
[root@openeuler mysql]# systemctl daemon-reload
[root@openeuler mysql]# systemctl start mysql
[root@openeuler mysql]# systemctl enable mysql
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /usr/lib/systemd/system/mysql.service.
[root@openeuler mysql]# systemctl status mysql
● mysql.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: disabled)
     Active: active (running) since Mon 2025-01-06 10:54:42 CST; 1min 27s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
   Main PID: 54359 (mysqld)
      Tasks: 36 (limit: 21560)
     Memory: 364.5M ()
     CGroup: /system.slice/mysql.service
             └─54359 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
验证
[root@openeuler mysql]# mysql -v
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
# 提示我缺少某个库,那我安装下
[root@openeuler mysql]# dnf install -y ncurses-libs
......
Package ncurses-libs-6.4-8.oe2403.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@openeuler mysql]# mysql -v
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
# 还报错,发现ncurses版本太新了,那就只能用链接方式处理下
[root@openeuler mysql]# ln -s /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
[root@openeuler mysql]# mysql -V
mysql  Ver 8.0.11 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)
# 成功!!!
登录数据库并修改密码
[root@openeuler mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.11

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.10 sec)
mysql> exit
Bye

# 测试修改后的密码
[root@openeuler mysql]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
# 成功!!!
配置数据库远程登录
[root@openeuler mysql]# mysql -uroot -p123456
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.04 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.10 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye