CentOS安装MySQL(解压包方式)

一、官网下载Linux通用的MySQL压缩包

二、上传解压

    上传到Linux服务器,并解压,我这里解压到/usr/local/mysql目录下

三、添加系统mysql组和用户mysql

# 添加系统组
groupadd mysql
# 添加用户
useradd -r -g mysql -s /bin/false mysql

四、开始安装

  1. 进入mysql目录
cd /usr/local/mysql

   

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

    2、修改当前目录(mysql)拥有者为mysql用户

chown -R mysql:mysql ./

     3、配置my.cnf文件

# 修改前内容
vi /etc/my.cnf
#-----------------------------------------------------------------------#
[mysqld]
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=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

# 修改后内容
vi /etc/my.cnf
#---------------------------------------------------------------------#
[client]
default-character-set=utf8
socket=/usr/local/mysql/data/mysql.sock
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/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=/usr/local/mysql/mysql-log/error.log
pid-file=/usr/local/mysql/data/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

    4、创建日志文件,创建前需要先创建目录

# 创建目录
mkdir /usr/local/mysql/mysql-log
# 创建文件,编辑后直接保存空文件就行
vi /usr/local/mysql/mysql-log/error.log

# 授权
chown mysql:mysql /usr/local/mysql/mysql-log/error.log

    5、初始化

bin/mysqld --initialize --user=mysql

# 如果出现下面报错
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
# 需要安装 libaio 依赖库

    6、支持安全连接

bin/mysql_ssl_rsa_setup

五、添加开机启动服务和mysql服务

# 添加mysql服务
cp support-files/mysql.server /etc/init.d/mysql
# 添加开机启动服务
chkconfig --add mysql

# 启动服务
service mysql start
# 关闭服务
service mysql stop

六、配置系统环境

vi /etc/profile
# 在最下面添加
export MYSQL_HOME=/usr/loca/mysql
export PATH=$MYSQL_HOME/bin:$PATH

# 保存后立即生效
source /etc/profile

七、修改root密码

# 登录,密码就是上面初始化的时候生成的
mysql -u root -p
# 修改密码
alter user 'root'@'localhost' identified by 'newpassword';
# 刷新权限
flush privileges;
--------------------------------------------------------------------


# 新增用户
create user 'test'@'%' identified by '123456';
# 给用户授权
grant all privileges on *.* to test@'%' with grant option;

# 如果使用navicat连接,加密方式不同,有时候需要使用navicat的加密方式
alter user 'test'@'%' identified with mysql_native_password by '123456';

八、原文连接

https://www.cnblogs.com/h--d/p/9556758.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值