centos7.6下安装mysql8.0.23

系统环境:centos7.6

mysql版本:8.0.23

下载地址:https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz

解压文件:

tar -xvf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz

文件夹改名:

mv mysql-8.0.23-linux-glibc2.12-x86_64 mysql

创建配置文件夹

mkdir /usr/local/mysql/conf

创建数据目录:

mkdir /data

mkdir /data/mysql

mkdir /data/mysql/binlog

创建用户:

useradd -s /sbin/nologin mysql

授权:

chown -R mysql /usr/local/mysql

chown -R mysql /data

设置环境变量:

vim /etc/profile.d/mysql.sh

输入内容:

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

加载配置:

source /etc/profile.d/mysql.sh

开机启动

vim /etc/systemd/system/mysqld.service

输入内容:

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/conf/my.cnf

LimitNOFILE = 5000

重新加载配置文件

systemctl daemon-reload

systemctl enable mysqld

 

创建Mysql 配置文件

vim /usr/local/mysql/conf/my.cnf

内容:

[client]
port=3306
socket=/usr/local/mysql/mysql.sock
default-character-set = utf8mb4

[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/data
port=3306
socket=/usr/local/mysql/mysql.sock
pid-file=/usr/local/mysql/mysql.pid
log-error=/data/mysql/mysql_error.log
log-bin=/data/mysql/binlog/binlog
max_connections = 300
character-set-server = utf8mb4
default-storage-engine = INNODB
lower_case_table_names = 1 
default_authentication_plugin = mysql_native_password

skip-host-cache
skip-name-resolve

#独立表空间
innodb_file_per_table = 1

#内存池
innodb_buffer_pool_size = 2G
innodb_flush_log_at_trx_commit = 1

[mysql]
default-character-set = utf8mb4
socket = /var/lib/mysql/mysql.sock

[mysqld_safe]

说明:

default_authentication_plugin:设置密码规则,caching_sha2_password是默认的身份验证插件,为方便使用 mysql_native_password

lower_case_table_names:忽略大写小,建议设置,方便业务

其余设置根据需求更改

 

初始化数据库

/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/conf/my.cnf --initialize --user=mysql

 

查询密码:

grep "password"  /data/mysql/mysql_error.log

#启动数据库

systemctl start mysqld

登录系统,密码为查询出的密码

mysql -uroot -p -S /usr/local/mysql/mysql.sock

修改密码:

alter user root@'localhost' identified WITH mysql_native_password by '123456';

设置远程连接

use mysql

update user set host ='%' where user ='root';

flush privileges;

 

posted @ 2022-02-12 13:40  陈苏乾  阅读(39)  评论(0编辑  收藏  举报