原始碼安裝mysql5.6.37

kisslfcr發表於2017-09-18
MYSQL 原始碼安裝:


修改引數檔案:
vi /etc/security/limits.conf
mysql soft nproc 2047
mysql hard nproc 16384
mysql soft nofile 1024
mysql hard nofile 65536
下載5.6.37原始碼
解壓後用cmake安裝:
cmake . -DCMAKE_INSTALL_PREEIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWICH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PREFSCHEMA_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 install


chown -R mysql:mysql /usr/local/mysql
export LANG=zh_CN.CB18030
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


編輯引數檔案
/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
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 =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=gbk


初始化db
/usr/local/mysql/scripts/mysql_install_db --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql


此處因為引數檔案手敲,出現了錯誤,需要重新初始化,步驟為:
1 刪除/usr/local/mysql/my.cnf
2 刪除/data/mysqldata/3306下除了my.cnf外的所有檔案,並重新建立此目錄下的binlog,data,tmp目錄
3 重新執行初始化指令碼


啟動mysql
mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
netstat -lnt|grep 3306
ps -ef|grep bin/mysql|grep -v grep


設定管理員使用者與密碼:
mysql
select user,host from mysql.user ;


delete from mysql.user where (user,host) not in (select 'root','localhost');
update mysql.user set user='system',password=password('xxxxxxxxx');
truncate table mysql.db;
flush privileges;
這樣就安全了。


以上是mysql使用原始碼安裝和配置root使用者的全過程

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29135257/viewspace-2145098/,如需轉載,請註明出處,否則將追究法律責任。

相關文章