演示环境介绍
操作系统:CentOS 6.7 (64位)
二进制包:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
MySQL 下载地址:http://dev.mysql.com/downloads/
1、下载MySQL
# mkdir /root/mysql
# cd /root/mysql
# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
2、解压
# cd /opt/
# mkdir mysql
# cd mysql
# tar zxvf /root/mysql/mysql-5.6.30....
# ln -s /opt/mysql/mysql-5.6.30-linux-glibc2.5-x86_64 /usr/local/mysql
# cd /usr/local/mysql
3、创建用户
# groupadd mysql
# useradd -g mysql -M -s /sbin/nologin mysql
4、环境变量
# vim /etc/profile
PATH=$PATH:/usr/local/mysql
# source /etc/profile
5、创建必须的目录
/data/mysql/mysql3376/
data 数据目录
tmp 临时文件
logs 二进制日志目录
# mkdir -p /data/mysql/mysql3376/{data,tmp,logs}
6、权限
# chown -R mysql:mysql /data/mysql/mysql3376/
# chown -R mysql:mysql /opt/mysql
# chown -R mysql:mysql /usr/local/mysql
7. 创建一个配置文件
[client] port = 3376 socket = /tmp/mysql3376.sock # The MySQL server [mysqld] # Basic port = 3376 user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql3376/data tmpdir = /data/mysql/mysql3376/tmp socket = /tmp/mysql3376.sock log-bin = /data/mysql/mysql3376/logs/mysql-bin log-error = error.log slow-query-log-file = slow.log skip-external-locking skip-name-resolve log-slave-updates
8、初始化
# cd /usr/local/mysql
# ./scripts/mysql_install_db --defaults-file=/etc/my.cnf
看到两次ok
9. 启动 & 关闭
启动:
# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
或者
# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf &
关闭:
# /usr/local/mysql/bin/mysqladmin -S /tmp/mysql3376.sock shutdown
10、 安全加固
# delete from mysql.user where user!='root' or host!='localhost';
# truncate table mysql.db;
# drop database test;
# flush privileges;
怎么确认mysql是启动起来的?
A 查看进程是否存在
# ps axu |grep mysqld
B 查看端口是不是监听正确
# ss -lnpt |grep mysqld
C 看看错误日志有无异常