演示環境介紹
操作系統: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 看看錯誤日志有無異常