1、首先从官网下载MySQL5.6.30源码包
# wget http://120.52.72.19/cdn.mysql.com/c3pr90ntc0td//Downloads/MySQL-5.6/mysql-5.6.31.tar.gz
2、解压到指定目录
# tar -zxvf mysql.5.6.31.tar.gz -C /usr/local/src
3、安装cmake及必须的软件包,因为自从mysql5.5以后就可以使用cmake来编译安装了,我们使用的操作系统是centos7.2
# yum groupinstall -y "Development tools"
# yum install -y cmake
4、新建msyql安装所使用的目录
mkdir -pv /data/mysqldata/3306/{data,tmp,binlog}
5、使用cmake编译安装
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PARTTION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DCOMPILATION_COMMENT='JSS for mysqltest' \
-DWITH_READLINE=ON \
-DSYSCONFDIR=/data/mysqldata/3306 \
-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock
如果接下来没有报错的话:
# make && make
6、新建mysql用户
# useradd mysql
7、添加权限
# chown -R mysql:mysql /data/mysqldata
# chown -R mysql:mysql /usr/local/mysql
8、接下来就可以初始化mysql了
首先进入到mysql用户:
# su - mysql
初始化mysql:
$ /usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql
如果看到两个OK 就表示初始化成功了
9、指定配置文件
$ vim /data/mysqldata/3306/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
user = mysql
socket = /tmp/mysql.sock
pid-file = /data/mysqldata/mysql.pid
basedir = /usr/local/mysql
datadir = /data/mysqldata/3306/data
tmpdir = /data/mysqldata/3306/tmp
open_files_limit = 10240
explicit_defaults_for_timestamp
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#Buffer
max_allowed_packet = 256M
max_heap_table_size = 256M
net_buffer_length = 8K
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
#Log
log-bin = /data/mysqldata/3306/binlog/mysql-bin
binlog_cache_size = 32M
max_binlog_cache_size = 512m
max_binlog_size = 512m
binlog_format = mixed
log_output = FILE
log-error = ../mysql-error.log
slow_query_log = 1
slow_query_log_file = ../slow_query.log
general_log = 0
general_log_file = ../general_query.log
expire-logs-days = 14
#InnoDB
innodb_data_file_path = ibdatal:2048M:autoextend
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_buffer_pool_size = 1024M
[mysql]
no-auto-rehash
prompt = (\u@\h) [\d]>\_
default-character-set = gbk
本配置文件仅供参考,具体还要根据实际环境而言
10、启动mysql
$ /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
$ ss -tnlp | grep 3306
如果能看到3306端口 就代表启动成功了
11、将mysql添加到系统的环境变量
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
12、最后做一些mysql的安全配置
删除mysql的用户,只留下一个本地连接的用户:
# mysql
mysql> delete from mysql.user where (user,host) not in (select 'root','localhost');
查看mysql用户:
mysql> select user,host,password from mysql.user;
将root用户重命名为system,并添加密码:
mysql> update mysql.user set user='system',password=password('123.com'):
清空mysql库下的db表:
mysql> truncate table mysql.db;
删除test测试库:
mysql> drop database test;
强制刷新是刚刚的操作生效:
mysql> flush privileges;
现在我们可以愉快的去玩我们的mysql数据库了
# mysql -usystem -p123.com
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于