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目录结构

  

目录 目录的内容
bin mysqld服务器,客户端和实用程序
docs 信息格式的MySQL手册
man Unix手册页
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;

猜你喜欢

转载自www.cnblogs.com/QicongLiang/p/9812041.html