MySQL源代码安装

MySQL源代码安装

标签(空格分隔): mysql


前置准备

关闭防火墙: 
    service iptables stop (临时关闭)
    chkconfig iptables off (重启后生效)
关闭SELINUX: 
    setenforce 0 (临时生效)  
    修改 /etc/selinux/config 下的 SELINUX=disabled (重启后永久生效)
        sestatus  检查状态

root用户执行安装组件

# yum -y install  gcc gcc-c++ gcc-g77 autoconf automake ncurses-devel cmake
# yum -y install wget gcc gcc-c++ cmake libaio-devel bison ncurses-devel perl-Data-Dumper
# mkdir -p /data/database/mysql   #MySQL安装目录  
# mkdir -p /data/database/mysql/data #存放数据  
# mkdir -p /data/database/mysql/log  #存放日志  
# mkdir -p /data/database/mysql/tmp  #存放临时文件  
# mkdir -p /data/database/mysql/data/log
  • 查看当前用户所在组并授权用户
# groupadd mysql 
# useradd -r -g mysql -s /sbin/nologin mysql
# chown -R mysql.mysql /data/database/mysql
  • 普通应用账号安装MySQL
$ tar -xzvf mysql-boost-5.7.20.tar.gz
$ cd mysql-5.7.20/
  • 编译MySQL
$ cmake . \  
 -DCMAKE_INSTALL_PREFIX=/data/database/mysql \  
 -DSYSCONFDIR=/data/database/mysql
 -DMYSQL_DATADIR=/data/database/mysql/data \  
 -DMYSQL_TCP_PORT=3336 
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \  
 -DWITH_PARTITION_STORAGE_ENGINE=1 \  
 -DWITH_FEDERATED_STORAGE_ENGINE=1 \  
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \  
 -DWITH_MYISAM_STORAGE_ENGINE=1 \  
 -DENABLED_LOCAL_INFILE=1 \  
 -DENABLE_DTRACE=0 \  
 -DDEFAULT_CHARSET=utf8 \  
 -DDEFAULT_COLLATION=utf8_general_ci \  
 -DWITH_EMBEDDED_SERVER=1  
 -DDOWNLOAD_BOOST=1 \  
 -DWITH_BOOST=/data/database/mysql-5.7.20/boost \ 
  • 安装
$ make && make install
  • 修改my.cnf配置文件
$ cd /data/database/mysql/
$ vim my.cnf
内容如下:
[client]  
socket = /data/database/mysql/run/mysql.sock  
default-character-set=utf8

[innotop]  
socket = /data/database/mysql/run/mysql.sock  

[mysql]  
prompt = \\u@\\d \\r:\\m:\\s>  
no-auto-rehash  
default-character-set=utf8

[mysqld_safe]  
pid-file = /data/database/mysql/run/mysqld.pid  

[mysqld]  

#### Baes dir ####  
basedir = /data/database/mysql  
datadir = /data/database/mysql/data 
tmpdir = /data/database/mysql/tmp  
socket = /data/database/mysql/run/mysql.sock  

#### Base configure info ####  
port = 3306  
character-set-server=utf8  
skip-name-resolve  
old_passwords = 0  
lower_case_table_names = 1  
open_files_limit = 65535  
read_rnd_buffer_size = 5M  
max_allowed_packet = 24M  
max_connect_errors = 50000  
max_connections = 1000  
max_user_connections = 950   
thread_cache_size=64  
table_open_cache=1024  
thread_stack=262144  
wait_timeout=864000  
explicit_defaults_for_timestamp=true  
#密码永不过期
default_password_lifetime=0

#### Log info ####  
log-error = /data/database/mysql/data/log/error.log  
slow_query_log=1  
slow_query_log_file= /data/database/mysql/data/log/slow.log 
log-slow-admin-statements  
long_query_time = 0.1  
slow_launch_time=1  

#### Binary log && Relay log ####  
binlog_format='MIXED'  
log-bin = /data/database/mysql/data/log/mysql-bin
log-slave-updates = 1  
relay-log = /data/database/mysql/data/log/mysqld-relay-bin  
relay-log-index = /data/database/mysql/data/log/mysqld-relay-bin.index  
master-info-file = /data/database/mysql/data/log/master.info  
relay-log-info-file = /data/database/mysql/data/log/relay-log.info  
max_binlog_size = 500M  
max_binlog_cache_size = 2G  


#### query cache ####  
query_cache_size = 100M  
query_cache_limit = 1K  
query_cache_min_res_unit = 1K  
query_cache_type=2  

#myisam  
concurrent_insert = 2  
key_buffer_size = 100M  
sort_buffer_size = 100K  
join_buffer_size = 100K  
read_buffer_size = 1M  
myisam_sort_buffer_size = 100M  

#innodb plugin  

#innodb  
default-storage-engine = InnoDB  
innodb_flush_method = O_DIRECT  
innodb_file_per_table = 1  
innodb_open_files=60000  
innodb_flush_log_at_trx_commit = 2  
innodb_lock_wait_timeout = 100  
innodb_additional_mem_pool_size = 20M  
innodb_buffer_pool_size = 16G  
innodb_log_buffer_size= 400M  
innodb_log_file_size = 100M  
innodb_log_files_in_group = 4  
innodb_file_io_threads = 4  
innodb_thread_concurrency = 16  
innodb_max_dirty_pages_pct = 50  
transaction-isolation = READ-COMMITTED  #### 降级数据库隔离级别,支持并发写入
innodb_data_file_path = ibdata1:12M;ibdata2:20M:autoextend  
# 通过命令ll -h mysql/data/ibdata1查看实际大小
innodb_buffer_pool_instances=4  
innodb_thread_concurrency=32  

### Server id ####  
log_bin_trust_function_creators=1  
read_only=0  
server_id=1
  • 主从复制相关
# 不同步哪些数据库  
binlog-ignore-db = mysql  
binlog-ignore-db = information_schema  
# 只同步哪些数据库,除此之外,其他不同步  
# binlog-do-db = urmp  
# 日志保留时间  
expire_logs_days = 30  
# 控制binlog的写入频率。每执行多少次事务写入一次  
# 这个参数性能消耗很大,但可减小MySQL崩溃造成的损失  
sync_binlog = 5
  • 将my.cnf覆盖/etc/my.cnf(需要root权限)
$ cp my.cnf  /etc/
  • 初始化数据库
$ cd /data/database/mysql/
$ scripts/mysql_install_db --user=urmp --basedir=/data/database/mysql --datadir=/data/database/mysql/data
--defaults=/etc/my.cnf
  • 启动数据库
$ bin/mysqld_safe  --defaults-file=/data/database/mysql/my.cnf
  • 修改数据库密码
$ bin/mysqladmin -u root password 'Xianzai.123'
$ bin/mysql -uroot -pXianzai.123
mysql>update mysql.user set password=password('Xianzai.123') where  user='root';flush privileges;
mysql>select host,user,password from mysql.user;
  • 关闭数据库
$ bin/mysqladmin -uroot -p shutdown
  • 添加MySQL至用户环境变量
$ vim ~/.bash_profile

新增

export MYSQL_HOME=/data/database/mysql
PATH=$PATH:$MYSQL_HOME/bin
$ source ~/.bash_profile
  • 将MySQL添加至系统服务(需要root权限)
$ cp support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动  
$ chmod 755 /etc/init.d/mysqld #增加执行权限  
$ chkconfig mysqld on #加入开机启动
  • 重启数据库连接测试
$ cd $MYSQL_HOME
$ bin/mysql -uroot -pXianzai.123

修改远程连接(======从机不可放开此设置======

mysql>use mysql;
mysql>update mysql.user set host='%' where user='root' and host='localhost';flush privileges;
mysql>grant all privileges  on *.* to root@'%' identified by "Xianzai.123";flush privileges;

MySQL5.7安装注意事项

MySQL 5.7 需要CMake 2.8.2,查看当前cmake版本

# cmake --version

cmake version 2.6-patch 4

# tar zxvf cmake-3.6.3.tar.gz
# cd cmake-3.2.2/
# ./bootstrap
# make && make install
# cmake --version

cmake version 3.6.3

  • MySQL5.7 CMake编译需要boost类库,可使用 -DDOWNLOAD_BOOST=1 -DWITH_BOOST= 参数将在指定路径查找

cd /usr/local/boost

wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

tar xfz /usr/local/boost/boost_1_59_0.tar.gz

  • 编译MySQL 5.7
$ cmake . 增加两个参数  -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页