一,准备依赖环境
# yum install perl
# yum install net-tools
# yum install libaio-devel
# yum install numactl-devel
二,下载mysql源并安装
# wget https://dev.mysql.com/get/mysql80-community-release-el8-3.noarch.rpm
安装mysql源:
# rpm -ivh mysql80-community-release-el8-3.noarch.rpm
三,yum安装mysql
安装:
# yum install -y mysql-community-server --nogpgcheck
配置启动:
# systemctl status mysqld.service
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: inactive (dead)Docs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.html
# systemctl start mysqld.service
# systemctl status mysqld.service
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since Fri 2026-04-24 16:43:05 CST; 3s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 202363 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Main PID: 202436 (mysqld)Status: "Server is operational"Tasks: 38Memory: 492.8MCGroup: /system.slice/mysqld.service└─202436 /usr/sbin/mysqldApr 24 16:42:54 ecm-qykwz-1-0002 systemd[1]: Starting MySQL Server...
Apr 24 16:43:05 ecm-qykwz-1-0002 systemd[1]: Started MySQL Server.
配置自启动:
# systemctl enable mysqld.service
# systemctl is-enabled mysqld.service
enabled
四,配置mysql账号:
1,得到临时密码
grep 'temporary password' /var/log/mysqld.log
2,用临时密码登录到mysql,修改密码并创建新账号
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.46Copyright (c) 2000, 2026, Oracle and/or its affiliates.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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';
Query OK, 0 rows affected (0.01 sec)mysql> CREATE USER 'root'@'%' IDENTIFIED BY '你的新密码';
Query OK, 0 rows affected (0.02 sec)mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)mysql> exit
Bye
3,重启mysql
# systemctl restart mysqld.service
# systemctl status mysqld.service
五,测试效果
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.46 MySQL Community Server - GPLCopyright (c) 2000, 2026, Oracle and/or its affiliates.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>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
