系统版本
[root@mysql01 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
要安装mysql-8.0.26
1.关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
关闭selinux
[root@mysql01 ~]# grep ^SELINUX= /etc/selinux/config
SELINUX=disabled
2.卸载mariadb依赖包
yum remove mariadb* -y
3.安装相关依赖包
yum install ncurses ncurses-devel libaio-devel openssl openssl-devel -y
4.建立MySQL用户账号
[root@mysql01 ~]# useradd mysql -s /sbin/nologin -M
[root@mysql01 ~]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
5.下载、解压mysql软件包,并做好软链接mysql到/usr/local。
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-el7-x86_64.tar.gz
tar -xf mysql-8.0.26-el7-x86_64.tar.gz
mv mysql-8.0.26-el7-x86_64 /usr/local/mysql
6.创建MySQL数据目录、配置文件(/etc/my.cnf)并授权
[root@mysql01 mysql]# 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@mysql01 mysql]# chown mysql.mysql /etc/my.cnf
7.创建MySQL数据目录并授权
[root@mysql01 mysql]# mkdir /data/3306/data -p
[root@mysql01 mysql]# chown -R mysql:mysql /data
[root@mysql01 mysql]# ls -ld /data/
8.配置PATH环境变量,并初始化MySQL数据库
echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
source /etc/profile
echo $PATH
9.初始化MySQL数据库
[root@mysql01 mysql]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data/
注:
重点知识1 : 之前不同版本的初始化命令异同
/usr/loc al/mysql/scripts/mysql_install_db #5.7之前
/usr/local/mysql/bin/mysqld #5.7和8.0初始化
重点知识2: --initialize和--initialize-insecure区别
--initialize: 会生成一个12位,4种密码复杂度临时管理员密码. 第一次登陆需要修改.
--initialize-insecure:管理员密码为空.
10.配置并启动MySQL数据库
[root@mysql01 mysql]# cd /usr/local/mysql/support-files/
[root@mysql01 support-files]# cp mysql.server /etc/init.d/mysqld
[root@mysql01 support-files]# systemctl enable mysqld
[root@mysql01 support-files]# systemctl start mysqld
[root@mysql01 support-files]# systemctl status mysqld
11.登录检查
mysql
标签:安装,mysql01,local,etc,usr,mysql,root From: https://www.cnblogs.com/wtyezi/p/17563117.html