Centos7 安装mysql8

1.下载安装包

mysql-8.0.13

2.解压(当前目录 /home )
# 解压
tar -Jxvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

# 重命名
mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql

3.创建用户组
# 创建组
groupadd mysql

# 创建用户
useradd -g mysql mysql

4.设置目录权限
chown -R mysql.mysql /home/mysql

5.创建data log目录
cd /home/mysql

# 创建目录
mkdir data log

# 创建mysql.pid
touch mysql.pid

# 创建mysql.log
touch log/mysql.log

# 设置权限
chown -R mysql  /home/mysql/mysql.pid
chgrp -R mysql  /home/mysql/mysql.pid

6.配置 my.cnf 文件
vim /etc/my.cnf

----------------------------------

[mysqld]
basedir=/home/mysql
datadir=/home/mysql/data
port=3306

[mysql_safe]
log-error=/home/mysql/logs/mysql.log
pid-file=/home/mysql/mysql.pid

7.初始化mysql
./mysqld --initialize --user=mysql --basedir=/home/mysql/ --datadir=/home/mysql/data

保存初始化密码

image
8.设置开机启动
# 进入support-files目录
cd /home/mysql/support-files/

# 拷贝
cp mysql.server /etc/init.d/mysql

# 设置权限
chmod +x /etc/init.d/mysql

# 设置开机启动
chkconfig --add mysql

9.创建软链接
ln -s /home/mysql/bin/mysql /usr/bin

10.启动mysql服务
service mysql start

image
11.登录mysql
mysql -u root -p

输入上面保存的密码

image
12.修改密码
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';

image
13.配置远程登录
# 使用mysql数据库
use mysql;

# 修改root允许远程访问
update user set host='%' where user='root';

# 允许远程登录
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
GRANT ALL ON *.* TO 'root'@'%';

# 刷新
flush privileges;

使用navicat测试链接

image

mysql安装成功

如果觉得还不错,点个赞呗 !O(∩_∩)O

你可能感兴趣的:(Centos7 安装mysql8)