#二进制方式安装MySQL,安装过程如下:
#(1)建立MySQL用户账号
首先以root身份登录到Linux系统中,然后执行如下命令创建mysql用户账号:
#<==创建mysql用户。
[root@xkf ~]# useradd mysql -s /sbin/nologin -M
#(2)下载、解压mysql软件包,并做好软链接mysql到/usr/local。
[root@xkf opt]# rz -E
rz waiting to receive.
[root@xkf opt]# ls
mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
[root@xkf opt]# tar xf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
[root@xkf opt]# ls
mysql-8.0.28-linux-glibc2.12-x86_64 mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
[root@xkf opt]# mv mysql-8.0.28-linux-glibc2.12-x86_64 /usr/local/mysql
#(3)创建MySQL数据目录、配置文件(/etc/my.cnf)并授权
#1)增加简易配置文件,后面在优化
[root@xkf opt]# cat > /etc/my.cnf<<'EOF'
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/3306/data
port=3306
socket=/tmp/mysql.sock
[client]
socket=/tmp/mysql.sock
EOF
[root@xkf opt]# chown mysql.mysql /etc/my.cnf
#2)创建MySQL数据目录并授权
[root@xkf opt]# mkdir -p /data/3306/data
[root@xkf opt]# chown -R mysql.mysql /data
[root@xkf opt]# ls -ld /data
drwxr-xr-x. 3 mysql mysql 18 Mar 22 16:21 /data
[root@xkf opt]# cd
3)配置PATH环境变量,并初始化MySQL数据库
#1) 配置PATH环境变量
[root@xkf ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
[root@xkf ~]# . /etc/profile
[root@xkf ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.8.0_331-amd64/bin
#2)初始化MySQL数据库
[root@xkf ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql \
--basedir=/usr/local/mysql --datadir=/data/3306/data
2023-08-25T07:25:27.889899Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.28) initializing of server in progress as process 4002
2023-08-25T07:25:27.901885Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-08-25T07:25:28.662721Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-08-25T07:25:29.809013Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
#个警告表示 root@localhost 用户以空密码创建成功不用管
#(4)配置并启动MySQL数据库
#1.设置MySQL启动脚本
[root@xkf ~]# cd /usr/local/mysql/support-files/
[root@xkf support-files]# cp mysql.server /etc/init.d/mysqld
[root@xkf support-files]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on
#2.启动MySQL数据库
[root@xkf support-files]# systemctl start mysqld
#3.检查MySQL数据库是否启动。
[root@xkf support-files]# netstat -lntup|grep 330
tcp6 0 0 :::33060 :::* LISTEN 10904/mysqld
tcp6 0 0 :::3306 :::* LISTEN 10904/mysqld
进入数据库
[root@xkf ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, 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>