下载地址
MySQL :: Download MySQL Community Serverhttps://dev.mysql.com/downloads/mysql/
下载
wget -c https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.0-linux-glibc2.17-x86_64.tar.xz
注意下glibc的版本
还要注意下Linux操作系统版本不同,配置有细微不同,根据报错提示即可解决!
准备
yum install -y libaio
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
tar xvf mysql-8.4.0-linux-glibc2.17-x86_64.tar.xz -C /var/lib/mv /var/lib/mysql-8.4.0-linux-glibc2.17-x86_64/ /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql/
echo 'export PATH=$PATH:/var/lib/mysql/bin' >> /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
初始化
tee /etc/my.cnf.d/server.cnf <<eof
[mysqld]
server-id=1
user=mysql
port=3306basedir = /var/lib/mysql
datadir = /var/lib/mysql/datalog-error = /var/lib/mysql/mysqld.log
pid-file = /var/lib/mysql/mysqld.pid
eofmysqld --initialize --user=mysql
服务管理
tee /usr/lib/systemd/system/mysqld.service <<eof
[Unit]
After=network.target
After=syslog.target[Install]
WantedBy=multi-user.target[Service]
User=mysql
Group=mysql
ExecStart=/var/lib/mysql/bin/mysqld --defaults-file=/etc/my.cnf.d/server.cnf
eofsystemctl daemon-reload && systemctl enable --now mysqld && systemctl status mysqld
密码
[root@oracle ~]# grep -i password /var/lib/mysql/mysqld.log
2024-05-02T13:33:56.609391Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: massiM=jt0ad
[root@oracle ~]# mysqladmin -uroot -p'massiM=jt0ad' password 'root'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
登录
[root@oracle ~]# mysql -uroot -p
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 10
Server version: 8.4.0 MySQL Community Server - GPLCopyright (c) 2000, 2024, 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> status
--------------
mysql Ver 8.4.0 for Linux on x86_64 (MySQL Community Server - GPL)Connection id: 10
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.4.0 MySQL Community Server - GPL
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /tmp/mysql.sock
Binary data as: Hexadecimal
Uptime: 9 min 10 secThreads: 2 Questions: 10 Slow queries: 0 Opens: 358 Flush tables: 3 Open tables: 54 Queries per second avg: 0.018