0
点赞
收藏
分享

微信扫一扫

centos7安装mysql8

guanguans 2022-04-27 阅读 75

1.下载mysql

在这里插入图片描述
或者

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz 
mv mysql-8.0.29-linux-glibc2.12-x86_64 /usr/loacl/mysql

2. 创建数据存放文件夹

cd /usr/local/mysql

mkdir data

3. 初始化数据库

./bin/mysqld  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

在这里插入图片描述
初始化完会生成一个临时密码,记得保存
mysqld –initialize-insecure可以生成无密码的root用户

4. 修改my.cnf文件

vim /etc/my.cnf

内容如下:

[mysqld]
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    socket = /usr/local/mysql/mysql.sock
    character-set-server=utf8
    port=3306

    symbolic-links=0

    log-error=/usr/local/mysql/data/mysql.log
    pid-file=/usr/local/mysql/data/mysql.pid
[client]
   socket = /usr/local/mysql/mysql.sock
   default-character-set=utf8

#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#[mysqld_safe]
#log-error=/usr/local/mysql/data/mysql.log
#pid-file=/usr/local/mysql/data/mysql.pid

#
# include all files from the config directory
./support-files/mysql.server start

在这里插入图片描述

报错

 vim /usr/local/mysql/support-files/mysql.server 

输入 /mysqld_safe 搜索,找到如下位置
在这里插入图片描述
添加 --user=root
在这里插入图片描述
不想改就得创建mysql用户:

5. 创建mysql用户(可选)

groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql/

在这里插入图片描述
重新初始化数据库

./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

再启动,成功
在这里插入图片描述

6. 创建mysql服务

将mysql.server复制到/etc/init.d/

cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

赋予权限

chmod +x /etc/init.d/mysql

创建chkconfig服务,可以开机自启

chkconfig --add mysql
service mysql start

7. 配置环境变量

vim /etc/profile

添加以下内容

export PATH=$PATH:/usr/local/mysql/bin

在这里插入图片描述
使配置生效:

source /etc/profile

8. 修改密码并允许远程访问

改密码为123456

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
use mysql
update user set host='%' where user='root';

在这里插入图片描述
完!

举报

相关推荐

0 条评论