Mysql数据库的二进制标准安装(简易版)
1. 官方下载mysql(版本5.7.26)
官网社区版最新下载地址
官网归档下载地址(历史)
tar -xzvf mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.6.38-linux-glibc2.12-x86_64 /opt/mysql57
2. 创建目录及用户
mkdir -p /data/mysql57/data /data/mysql57/binlog /data/mysql57/logs /data/mysql57/pid /data/mysql57/socks
/opt/mysql57
useradd mysql
chown -R mysql. /data /opt/mysql57
export PATH=/opt/mysql57/bin:$PATH
?? centos7机器,需要检查下是否有mariradb包
rpm -qa | grep mariadb
yum remove mariadb
3. 依赖安装及数据初始化
yum -y install zlib-devel
- 不安全的初始化(无密码校验规则)
mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql57 --datadir=/data/mysql57/data
4. 简单写一个配置文件(支持启动)
[mysqld]
user=mysql
basedir=/opt/mysql57
datadir=/data/mysql57/data/
socket=/data/mysql57/socks/mysql.sock
server_id=51 # 数据库标识,可以理解为局域网内的ip地址,在相同环境下要有唯一性
[mysql]
socket=/data/mysql57/socks/mysql.sock
5.使用systemctl管理mysqld
- vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
PIDFile=/data/mysql57/pid/mysqld.pid
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Needed to create system tables
#ExecStartPre=/usr/bin/mysqld_pre_systemd
# Start main service 指定mysqld目录
ExecStart=/opt/mysql57/bin/mysqld --daemonize --pid-file=/data/mysql57/pid/mysqld.pid
#注意这里要加上 --daemonize
# Use this to switch malloc implementation
#EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
记得重新载入 systemctl daemon-reload #重新载入
6.尝试使用systemctl工具启动数据
# 启动数据库服务
systemctl start mysqld
# 查看服务状态
systemctl status mysqld
# 停止服务
systemctl stop mysqld
7. 进入数据库并设置密码
mysql -u root -p # 回车即可,不需要输入密码
show databases;
alter user root@localhost identified by 'oracle';
flush privileges;
create user 'root'@'%' identified by 'oracle';
grant all on *.* to 'root'@'%';
flush privileges;
|