1.下载Mysql社区版(备注说明Windows下载,则需要上传至/home/mysql/目录下)
登录Mysql官网:MySQL 点击“DOWNLOADS”
选择“MySQL Community (GPL) Downloads”
选择社区服务器版,即点击“MySQL Community Server”
选择对应的版本,本文是计划安装在CentOS上,所以,选择通用版【小伙伴们,可以依据实际情况选择】。
具体的版本,本文选择“ Linux - Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive”
如果小伙伴们有兴趣,可以成为注册用户;本人不打算注册,选择如下:
至此,就可以下载Mysql安装包了。下载完成后,上传安装包到/home/mysql/目录下。
2.创建mysql用户和mysql用户组
[root@localhost ~]#
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
[root@localhost ~]# passwd mysql
Changing password for user mysql.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#
3.解压mysql压缩包到/usr/loacl/mysql目录
[root@localhost ~]# tar -xvf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
[root@localhost ~]# mv mysql-8.0.29-linux-glibc2.12-x86_64 /usr/local/mysql8
4.创建目录
[root@localhost ~]# cd /usr/local/mysql8/
[root@localhost mysql8]# mkdir conf #配置文件目录
[root@localhost mysql8]# mkdir data #数据文件目录
[root@localhost mysql8]# mkdir ibdata #ibdata文件目录
[root@localhost mysql8]# mkdir redolog #redolog文件目录
[root@localhost mysql8]# mkdir -p mysqllog/logfile #日志文件目录
[root@localhost mysql8]# mkdir -p mysqllog/relaylog #relaylog文件目录
[root@localhost mysql8]# mkdir -p mysqllog/binlog #binlog文件目录
5.创建my.cnf配置文件
vi /usr/local/mysql8/conf/my.cnf
[mysqld]
server-id=134
port=13306
basedir=/usr/local/mysql8
datadir=/usr/local/mysql8/data
socket=/usr/local/mysql8/mysql.sock
character-set-server=utf8mb4
max_connections = 1500
binlog_format=row
log-bin=/usr/local/mysql8/mysqllog/binlog
slow_query_log_file=/usr/local/mysql8/mysqllog/logfile/slow-query.log
log-error=/usr/local/mysql8/mysqllog/logfile/mysql-err.log
relay-log-index=/usr/local/mysql8/mysqllog/relaylog/slave-relay-bin.index
relay-log=/usr/local/mysql8/mysqllog/relaylog/relaylog-binlog
gtid_mode=ON
enforce_gtid_consistency = ON
event_scheduler=1
6.更改目录权限
[root@localhost bin]# chown -R mysql:mysql /usr/local/mysql8/
7.初始化数据库
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql8 --datadir=/usr/local/mysql8/data
8.启动数据--mysql用户执行
[mysql@localhost ~]$ /usr/local/mysql8/bin/mysqld_safe --defaults-file=/usr/local/mysql8/conf/my.cnf --user=mysql &
9.修改初始化密码--mysql用户执行
[mysql@localhost bin]$ ./mysql -h 127.0.0.1 -uroot -P13306 -S /usr/local/mysql8/mysql.sock -p
输入密码:【初始化密码在初始化数据库时,最后一行:2022-05-08T08:52:11.257229Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 7s4vui&_Ew#q】
mysql> alter user 'root'@'localhost' identified by 'mysql'; #修改密码为:mysql
重新登录数据:
[mysql@localhost bin]$ ./mysql -h 127.0.0.1 -uroot -P13306 -S /usr/local/mysql8/mysql.sock -pmysql
至此,mysql数据已经安装完成。