centos7 安装mysql 8.0.23

  1. 首先mysql的安装包
  2. mysql官网
  3. 网盘 mysql 8.0.23
  4. 提取码
2cib
  1. 直接下载地址
  2. 上传文件
  3. 创建目录
mkdir -p /export/server
  1. 解压文件

-c 表示解压到指定目录(大写)

tar -xvf mysql-8.0.23-linux-glibc2.12-x86_64/ -C  /export/server



创建用户组以及用户和密码
     groupadd mysql
     useradd -g mysql mysql



授权用户 (如:下列配置my.cnf 时指定的目录都需给mysql 用户授权)
	chown -R mysql.mysql /export/server/mysql-8.0.23-linux-glibc2.12-x86_64



创建 data 数据存储目录
    mkdir -p /export/server/mysql-8.0.23-linux-glibc2.12-x86_64/data
切换到bin 目录下
     cd  /export/server/mysql-8.0.23-linux-glibc2.12-x86_64/bin
初始化基础信息  切记切记切记mysql8 一定要在初始化时设置 不区分大小写,不然后续修改和删除重装没区别
初始化后在原始my.con 下lower_case_table_names = 1 是无效的,所以一定要在初始化时加上  --lower-case-table-names=1
 ./mysqld --user=mysql --basedir=/export/server/mysql-8.0.23-linux-glibc2.12-x86_64 --datadir=/export/server/mysql-8.0.23-linux-glibc2.12-x86_64/data/ --initialize  --lower-case-table-names=1
  1. 得到系统初始化随机默认密码,此处得记录下密码
  2. centos8安装 postgresql 14 Centos8安装MySQL 8.0.23_数据库

  3. 编辑my.cnf文件
vi /etc/my.cnf

修改之前

centos8安装 postgresql 14 Centos8安装MySQL 8.0.23_linux_02


修改之后

centos8安装 postgresql 14 Centos8安装MySQL 8.0.23_linux_03

[mysqld]
#设置mysql的安装目录
basedir=/export/server/mysql-8.0.23-linux-glibc2.12-x86_64
#设置mysql数据库的数据的存放目录  
datadir=/export/server/mysql-8.0.23-linux-glibc2.12-x86_64/data
#设置客户端默认字符集
character-set-server=UTF8MB4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
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=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
  1. 添加mysqld服务到系统 授权以及添加服务
进入主目录
 cd /export/server/mysql-8.0.23-linux-glibc2.12-x86_64
添加mysqld服务到系统
 cp -a ./support-files/mysql.server /etc/init.d/mysql
授权以及添加服务
 chmod +x /etc/init.d/mysql
 chkconfig --add mysql

centos8安装 postgresql 14 Centos8安装MySQL 8.0.23_linux_04

  1. 启动服务 建立服务同步连接
service mysql start #服务启动
 service mysql status #查看服务状态
 service mysql stop #停止服务
 service mysql restart #重启服务
  1. mysql 启动报错
  2. centos8安装 postgresql 14 Centos8安装MySQL 8.0.23_mysql_05

  3. 还是配置文件问题
    vi /etc/my.cnf
[mysqld]
#设置mysql的安装目录
basedir=/export/server/mysql-8.0.23-linux-glibc2.12-x86_64
#设置mysql数据库的数据的存放目录  
datadir=/export/server/mysql-8.0.23-linux-glibc2.12-x86_64/data
#设置客户端默认字符集
character-set-server=UTF8MB4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#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=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d
#设置是否区分大小写(初始化后此参数在这里也必须存在)
lower_case_table_names=1
# 默认使用“mysql_native_password”插件认证 
default_authentication_plugin=mysql_native_password
#注释mysqld_safe 下的所有配置  系统会输出到   datadir目录下
#[mysqld_safe]
#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
  1. 建立软链接
ln -s /export/server/mysql-8.0.23-linux-glibc2.12-x86_64/bin/mysql /usr/bin/
  1. 登录mysql 并修改密码
#进入mysql 控台
mysql  mysql -uroot -p
#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';   
#刷新权限
flush privileges;

centos8安装 postgresql 14 Centos8安装MySQL 8.0.23_mysql_06

  1. 配置外网连接授权
#选择mysql数据库
 use mysql;
 #修改root 用户的连接地址现在  localhost 为本机 也可指定固定ip 此处 % 开启所有ip访问
 update user set host='%' where user='root';
 #刷新权限
 flush privileges;