在CentOS中安装Mysql数据库
1.下载Mysql社区版(备注说明Windows下载,则需要上传至/home/mysql/目录下)
首先下载putty
官网
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
第二步 传文件
进入安装的路径,我按在d盘的putty文件夹下,所以进入d盘路径
在这里插入图片描述
然后输入,pscp空格你本地的文件空格root@服务器公网ip:/要把这个文件传到服务器的那个地方
(root应该是服务器的用户名,没改过就是root)
D:\putty>pscp c:/mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz root@106.14.93.219:/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
如提示错误:error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
这个错误提示表明缺少 libaio.so.1
共享库文件,这是 MySQL 运行所需要的依赖库之一。
要解决这个问题,可以按照以下步骤进行操作:
sudo yum install libaio