Mysql 5.6.35 源码安装

安装环境

系统:CenteOS 7.4

安装过程

删除已有包

shell> rpm -qa | grep mysql
shell> rpm -e --nodeps xxx(匹配到的mysql名称)

安装依赖包

shell> yum install -y wget cmake gcc* c++* autoconf automake
shell> yum install -y zlib*  libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* perl

设置用户操作系统资源的限制

##在文件/etc/security/limits.conf的最后增加以下内容
mysql            soft    nproc           2047
mysql            hard    nproc           16384
mysql            soft    nofile          1024
mysql            hard    nofile          65536

添加用户和组

shell> groupadd mysql
shell> useradd -g mysql mysql

从源码生成特定指令

从http://mirrors.sohu.com/mysql下载

# 下载和解压
shell> mkdir -p /home/q/mysql
shell> cd /home/q/mysql
shell> wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35.tar.gz
shell> tar -zxvf mysql-5.6.35.tar.gz

产生标准的建构档

shell> cd mysql-5.6.35
shell>
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_MYISAM_STORAGE_ENGINE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=ON \
-DMYSQL_DATADIR=/var/mysql/data \
-DSYSCONFDIR=/data/mysqldata/3306 \
-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock

如果执行cmake报错或者参数变更,需要重新配置,可执行下列步骤

通过rm命令,删除源码包目录下的Cmakecache.txt文件,然后重新执行cmake命令

rm -if CMakeCache.txt
#重新执行 cmake ...

编译和安装

make && make install

修改MySQL软件所在目录的拥有者为 mysql 用户

chown -R mysql:mysql /usr/local/mysql

修改mysql用户的环境变量,编译.bash_profile文件

vi /home/mysql/.bash_profile
#在该文件的最后增加下面两行
export LANG=zh_CN.GB18030
export PATH=/usr/local/mysql/bin:$PATH

创建目录

cd /data/
mkdir -p /data/mysqldata/{3306/{data,tmp,binlog},backup,scripts}
chown -R mysql:mysql mysqldata
su - mysql
cd /usr/local/mysql

创建my.cnf配置文件并编辑

touch /data/mysqldata/3306/my.cnf
vi /data/mysqldata/3306/my.cnf
# 添加下列参数
[client]
port = 3306
socket = /data/mysqldata/3306/mysql.sock
# The MySQL server
[mysqld]
port = 3306
user = mysql
socket = /data/mysqldata/3306/mysql.sock
pid-file = /data/mysqldata/3306/mysql.pid
basedir = /usr/local/mysql
datadir = /data/mysqldata/3306/data
tmpdir = /data/mysqldata/3306/tmp
open_files_limit = 10240
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
explicit_defaults_for_timestamp=true
[mysql]
no-auto-rehash
prompt = (\u@\h) [\d]>\_
default-character-set = gbk

初始化mysql

/usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql

启动数据库服务

shell> cd /usr/local/mysql
shell> bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &

查看3306端口是否已分配并检查mysqld相关进程是否存在的方式

netstat -lnt | grep 3306
ps -ef | grep bin/mysql | grep -v grep

建立系统路径

ln -s /usr/local/mysql/bin/mysql /usr/bin

初次进入MySQL

# 首次进入
mysql
select user,host from mysql.user; #查询用户
# 为保证安全删除其他用户
delete from mysql.user where (user,host) not in (select 'root','localhost'); 
# 修改现有用户
update mysql.user set user='root',password=password('111111'); 
# 删除test库的权限
truncate table mysql.db;
# 刷新权限
flush privileges;

打开防火墙

-A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT
vi /data/mysqldata/scripts/mysql_env.ini
#set env
MYSQL_USER=root
MYSQL_PASS='111111'
# check parameter
if [ $# -ne 1]
then
        HOST_PORT=3306
else
        HOST_PORT=$1
fi
chmod 600 /data/mysqldata/scripts/mysql_env.ini
vi /data/mysqldata/scripts/mysql_db_startup.sh

你可能感兴趣的:(mysql)