OS:CentOS 7.4 最小化安裝以及必要一些包mysql
1# 下載MySQL 5.6 源碼:sql
cd /software wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.41.tar.gz
2# OS 修改limits.conf,再最後添加數據庫
vi /etc/security/limits.conf mysql soft nproc 2047 mysql hard nproc 16384 mysql soft nofile 1024 mysql hard nofile 65536
3# 創建mysql用戶和組bash
groupadd -g 1001 mysql useradd -g 1001 -u 1001 -d /home/mysql mysql
4# 解壓MySQL源碼socket
cd /software tar zxf MySQL-5.6/mysql-5.6.41.tar.gz cd mysql-5.6.41
5# 執行cmake,生成編譯配置文件tcp
cmake . \ -DCMAKE_INSTALL_PREFIX=/opt/mysql-5.6.41 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DMYSQL_USER=mysql \ -DWITH_DEBUG=0
6# 編譯和安裝ide
make && make install
7# 修改/opt/mysql-5.6.41的屬主和屬組code
cd /opt chown -R mysql:mysql /opt/mysql-5.6.41
8# 創建軟鏈接以便將來版本更新orm
cd /opt ln -s /opt/mysql-5.6.41 mysql
9# 修改mysql用戶profile,將/opt/mysql/bin添加到PATHip
su - mysql vi ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=/opt/mysql/bin:$PATH:$HOME/.local/bin:$HOME/bin export PATH
10# 創建數據路徑 #也爲了多版本作準備, root用戶下
mkdir -p /data/mysqldata/{3306/{data,tmp,binlog},backup,scripts} chown -R mysql:mysql /data/mysqldata
11# 創建參數文件my.cnf
su - mysql cd /data/mysqldata/3306 touch my.cnf vi my.cnf ##my.cnf文件以下 [client] port = 3306 socket = /data/mysqldata/3306/mysql.sock [mysqld] port = 3306 user = mysql socket = /data/mysqldata/3306/mysql.sock pid-file = /data/mysqldata/3306/mysql.pid basedir = /opt/mysql datadir = /data/mysqldata/3306/data tmpdir = /data/mysqldata/3306/tmp open_files_limit = 1024 explicit_defaults_for_timestamp = 1 sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION" #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 = ibdata1: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 = utf8
12# 初始化數據庫,由於沒有在CMAKE的時候指定innodb信息,因此跟上--defaults-file
/opt/mysql/scripts/mysql_install_db \ --datadir=/data/mysqldata/3306/data \ --basedir=/opt/mysql \ --defaults-file=/data/mysqldata/3306/my.cnf
13# 啓動數據庫
mysqld_safe --defaults-file='/data/mysqldata/3306/my.cnf' & netstat -lnt | grep 3306 tcp6 0 0 :::3306 :::* LISTEN ps -ef | grep mysql root 26547 2324 0 05:54 pts/0 00:00:00 su - mysql mysql 26548 26547 0 05:54 pts/0 00:00:00 -bash mysql 28998 26548 0 06:41 pts/0 00:00:00 /bin/sh /opt/mysql/bin/mysqld_safe \ --defaults-file=/data/mysqldata/3306/my.cnf mysql 29464 28998 0 06:41 pts/0 00:00:02 /opt/mysql/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --basedir=/opt/mysql --datadir=/data/mysqldata/3306/data --plugin-dir=/opt/mysql/lib/plugin --log-error=../mysql-error.log --open-files-limit=1024 --pid-file=/data/mysqldata/3306/mysql.pid --socket=/data/mysqldata/3306/mysql.sock --port=3306