一、官网下载Linux通用的MySQL压缩包
二、上传解压
上传到Linux服务器,并解压,我这里解压到/usr/local/mysql目录下
三、添加系统mysql组和用户mysql
# 添加系统组
groupadd mysql
# 添加用户
useradd -r -g mysql -s /bin/false mysql
四、开始安装
- 进入mysql目录
cd /usr/local/mysql
目录 | 目录内容 |
bin | mysqld服务器,客户端和实用程序 |
docs | 信息格式的MySQL手册 |
man | 手册页 |
include | 包含(标题)文件 |
lib | lib库 |
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