centos环境下安装mysql-8.0.12

安装包请自行在官网下载

https://dev.mysql.com/downloads/mysql/

 

 

一:安装相关依赖包

yum  -y  install  gcc  gcc-c++  ncurses-devel  perl

 

二:环境配置

添加系统mysql组和mysql用户:

groupadd mysql

useradd -r -g mysql -s /bin/false mysql

 

将mysql命令加进环境变量

打开profile

vim /etc/profile

PATH=/tools/mysql-8.0.12-el7-x86_64/bin:$PATH
export PATH

读取profile配置

source /etc/profile

 

三:安装mysql

解压安装包

mysql目录结构

  

 

目录目录的内容
binmysqld服务器,客户端和实用程序
docs信息格式的MySQL手册
manUnix手册页
include包含(标题)文件
lib图书馆
share用于数据库安装的错误消息,字典和SQL
support-files其他支持文件

 

修改当前目录拥有者为mysql用户:

chown -R mysql:mysql ./

 

配置mysql配置文件

vim  /etc/my.cnf

[client]
port=3306 # 设置mysql客户端连接服务端时默认使用的端口

default-character-set=utf8
socket=/tools/mysql-8.0.12-el7-x86_64/data/mysql.sock

 

[mysqld]

basedir=/tools/mysql-8.0.12-el7-x86_64 # 设置mysql的安装目录
datadir=/tools/mysql-8.0.12-el7-x86_64/data

socket=/tools/mysql-8.0.12-el7-x86_64/data/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=/data/log/mysql-log/error.log
# pid-file=/data/soft/mysql-8.0.12-el7-x86_64/data/mysql.pid
#
# #
# # include all files from the config directory
# #
# !includedir /etc/my.cnf.d

 

初始化数据目录,包括mysql包含初始MySQL授权表的 数据库,该表确定如何允许用户连接到服务器     

bin/mysqld

--initialize-insecure  --user=mysql    (不设置密码)

 

复制启动脚本

cp support-files/mysql.server /etc/init.d/mysql

启动数据库

 /etc/init.d/mysql  start

 

修改root密码

进入mysql

mysql  -u  root   -p

 

ALTER USER 'root'@'localhost' IDENTIFIED BY 'passowrd' ;

ALTER USER 'root'@'%' IDENTIFIED BY 'passowrd' ;

flush privileges;

 

MySQL8.0的用户授权和之前有所区别,老版本的常用授权语句在8.0中会报错:

MySQL8.0之前版本:

GRANT ALL ON *.* TO `wangwei`@`127.0.0.1` IDENTIFIED BY 'passowrd' WITH GRANT OPTION;

MySQL8.0版本:

CREATE USER `wangwei`@`127.0.0.1` IDENTIFIED BY 'passowrd';

GRANT ALL ON *.* TO `wangwei`@`127.0.0.1` WITH “GRANT OPTION”;

 

mysql-8.0以后的版本,用户密码认证的默认方式修改成caching_sha2_password。

①:此更改仅适用于安装或升级到MySQL 8.0或更高版本后创建的新帐户。对于已升级安装中已存在的帐户,其身份验证插件保持不变,还是mysql_native_password。当然也可以使用命令将用户的身份验证改为:caching_sha2_password;

如:ALTER USER user  IDENTIFIED WITH caching_sha2_password  BY 'password';

②:新安装MySQL8.0的数据库默认是使用caching_sha2_password身份验证的,必须使用5.8版本安装包内的客户端软件登录数据库,如果要更改root用户的身份认证方式,可以使用命令:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password  BY 'password';

 

caching_sha2_password兼容性问题和解决方案

如果您的MySQL安装必须服务于8.0之前的客户端,并且在升级到MySQL 8.0或更高版本后遇到兼容性问题,解决这些问题并恢复8.0之前的兼容性的最简单方法是重新配置服务器以恢复到以前的默认身份验证插件(mysql_native_password)。例如,在配置文件my.cnf中使用以下行:

[mysqld]

default_authentication_plugin=mysql_native_password

 

转载于:https://www.cnblogs.com/QicongLiang/p/9812041.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值