官网下载安装包
https://dev.mysql.com/downloads/mysql/
安装依赖
代码语言:javascript复制yum install libaio-devel
创建用户
代码语言:javascript复制groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
解压安装包
代码语言:javascript复制tar xf mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar
tar xf mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz
mv mysql-8.0.27-linux-glibc2.17-x86_64-minimal /usr/local/mysql
创建数据目录并设置权限
代码语言:javascript复制mkdir /data/mysql
mkdir /var/log/mysql/
touch /var/log/mysql/mysql.log
chown -R mysql.mysql /data/mysql/
chown -R mysql.mysql /usr/local/mysql/
chown -R mysql.mysql /var/log/mysql/
修改配置文件
代码语言:javascript复制vim /etc/my.cnf
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/data/mysql/mysql.sock
innodb_file_per_table=on
symbolic-links=0
log-error=/var/log/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
初始化数据库并启动服务
代码语言:javascript复制cd /usr/local/mysql/
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
初始化完成后,记录下默认的root密码
登录数据库并修改默认密码
代码语言:javascript复制/usr/local/mysql/bin/mysql -uroot -p
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
mysql> flush privileges;
设置远程访问权限
代码语言:javascript复制mysql> create user 'root'@'%' identified with mysql_native_password by '123456';
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
mysql> flush privileges;