编译安装
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/opt/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-DWITH_BOOST=/opt/mysql-5.7.40/boost/boost_1_59_0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=system \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=1
创建mysql用户、用户组及目录
groupadd -r mysql && useradd -r -g mysql -s /bin/false -M mysql
设置权限并初始化 MySQL 系统授权表
chown -R mysql:mysql .
MySQL 5.7.6之前的版本执行这个脚本初始化系统数据库
./bin/mysql_install_db --user=mysql --basedir=/root/mysql --datadir=/opt/data
5.7.6之后版本初始系统数据库脚本
mysqld --initialize-insecure --user=mysql --basedir=/root/mysql --datadir=/opt/data
注意:
MySQL之前版本mysql_install_db是在mysql_basedir/script下,MySQL 5.7直接放在了mysql_basedir/bin目录下。
"--initialize"已废弃,生成一个随机密码(~/.mysql_secret)
"--initialize-insecure"不会生成密码
"--datadir"目录下不能有数据文件
生成密钥到/opt/data
mysql_ssl_rsa_setup
创建配置文件
cat > /etc/my.cnf << EOF
[client]
port=3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
skip-external-locking
skip-name-resolve
user=mysql
port=3306
basedir=/usr/local/mysql
datadir=/data/mysql
tmpdir=/usr/local/mysql/temp
# server_id = .....
socket=/usr/local/mysql/mysql.sock
log-error=/usr/local/mysql/logs/mysql_error.log
pid-file=/usr/local/mysql/mysql.pid
open_files_limit=10240
back_log=600
max_connections=500
max_connect_errors=6000
wait_timeout=605800
#open_tables=600
#table_cache = 650
#opened_tables = 630
max_allowed_packet=32M
sort_buffer_size=4M
join_buffer_size=4M
thread_cache_size=300
query_cache_type=1
query_cache_size=256M
query_cache_limit=2M
query_cache_min_res_unit=16k
tmp_table_size=256M
max_heap_table_size=256M
key_buffer_size=256M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=64M
lower_case_table_names=1
default-storage-engine=INNODB
innodb_buffer_pool_size=2G
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_flush_method=O_DIRECT
#####################
thread_concurrency=32
long_query_time=2
slow-query-log=on
slow-query-log-file=/usr/local/mysql/logs/mysql-slow.log
[mysqldump]
quick
max_allowed_packet=32M
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
EOF
配置MySQL服务
cp /root/mysql/support-files/mysql.server /etc/init.d/mysqld