lnmp-mysql 源码安装
下载对应包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20.tar.gz
wget --no-check-certificate http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
创建配置目录存放mysql 相关配置:
mkdir -p "/data1/data/mysql/5.7.21"
mkdir -p "/data1/server/mysql/5.7.21/var/run"
mkdir -p "/data1/server/mysql/5.7.21/bin"
mkdir -p "/data1/server/mysql/5.7.21/conf"
mkdir -p "/data1/server/mysql/5.7.21/data"
mkdir -p "/data1/server/mysql/5.7.21/logs/binlog"
安装依赖
yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel
解压mysql 压缩包 tar -zxvf mysql-5.7.20.tar.gz
将boost的压缩包解压 tar -zxvf boost_1_59_0.tar.gz
移动boost_1_59_0到指定文件内(主要是根据cmake配置)
mv boost_1_59_0 /data1/server/mysql/5.7.21/boost_1_59_0
进入mysql 解压后的文件夹 cmake 编译
cmake . -DCMAKE_INSTALL_PREFIX=/data1/server/mysql/5.7.21/bin \
-DMYSQL_DATADIR=/data1/data/mysql/5.7.21 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/data1/server/mysql/5.7.21/boost_1_59_0 \
-DSYSCONFDIR=/data1/server/mysql/5.7.21/conf \
-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
如果出现下面的提示就表示成功生成了编译环境:
-- Configuring done
-- Generating done
使用make进行编译:
make
编译完成后,会出现如下信息:
[100%] Building CXX object sql/CMakeFiles/udf_example.dir/udf_example.cc.o
Linking CXX shared module udf_example.so
[100%] Built target udf_example
[100%] Built target my_safe_process
(六)、安装MySQL:
make install
三、初始化数据库
编写 /data1/server/mysql/5.7.21/conf/my.cnf
[mysql]
default-character-set = utf8
socket = <MYSQL_DIST_DIR>/var/run/mysql.sock
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
default-storage-engine = InnoDB
sql_mode =
user = <MYSQL_USER>
port = <MYSQL_PORT>
socket = <MYSQL_DIST_DIR>/var/run/mysql.sock
basedir = <MYSQL_DIST_DIR>/bin
datadir = <MYSQL_DATA_DIR>
log-error = <MYSQL_DIST_DIR>/logs/mysql_error.log
pid-file = <MYSQL_DIST_DIR>/var/run/mysql.pid
log-bin = <MYSQL_DATA_DIR>/binlog
slow_query_log_file = <MYSQL_DIST_DIR>/logs/slow.log
open_files_limit = 60000
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
back_log = 600
max_connections = 6000
max_connect_errors = 6000
external-locking = FALSE
max_allowed_packet = 64M
sort_buffer_size = 6M
join_buffer_size = 6M
thread_cache_size = 600
query_cache_size = 512M
query_cache_limit = 4M
query_cache_min_res_unit = 2k
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
log-slave-updates
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 16M
max_binlog_size = 1G
expire_logs_days = 7
key_buffer_size = 512M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 256M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 2
interactive_timeout = 900
wait_timeout = 900
skip-name-resolve
server-id = 2001
innodb_buffer_pool_size = 1224M
innodb_data_file_path = ibdata1:256M:autoextend
innodb_thread_concurrency = 12
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
slow-query-log = ON
long_query_time = 4
explicit_defaults_for_timestamp=true
[mysqldump]
quick
max_allowed_packet = 64M
socket = <MYSQL_DIST_DIR>/var/run/mysql.sock
port = <MYSQL_PORT>
sed -i "s#<MYSQL_USER>#xxxx#g" /data1/server/mysql/5.7.21/conf/my.cnf
sed -i "s#<MYSQL_PORT>#3306#g" /data1/server/mysql/5.7.21/conf/my.cnf
sed -i "s#<MYSQL_DIST_DIR>#/data1/server/mysql/5.7.21#g" /data1/server/mysql/5.7.21/conf/my.cnf
sed -i "s#<MYSQL_DATA_DIR>#/data1/data/mysql/5.7.21#g" /data1/server/mysql/5.7.21/conf/my.cnf
初始化数据库
/data1/server/mysql/5.7.21/bin/bin/mysqld \
--defaults-file=/data1/server/mysql/5.7.21/conf/my.cnf \
--initialize \
--user=xxxx \
--basedir=/data1/server/mysql/5.7.21/bin \
--datadir=/data1/data/mysql/5.7.21
重置密码
启动服务
/data1/server/mysql/5.7.21/bin/bin/mysqld_safe --defaults-file=/data1/server/mysql/5.7.21/conf/my.cnf > /dev/null 2>&1 &
获取root 账号密码
ROOT_PASSWORD=`cat /data1/server/mysql/5.7.21/logs/mysql_error.log | grep 'A temporary password' | sed 's/\(.*\)root@localhost: \(.*\)/\2/g'`
/data1/server/mysql/5.7.21/bin/bin/mysql --connect-expired-password -u"root" -p"{ROOT_PASSWORD}"
set password=password("123456");