官方网站中下载源码包;
https://dev.mysql.com/downloads/mysql/
选择下载源码包:
由于官网下载较慢,我选择使用搜狐镜像站进项下载..速度真的快的不是一星半点:
电梯:
http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17.tar.gz
下载下来后计算一下md5和上图比对一下.不对就重新下载一次.不过一般都没有什么问题.
创建用户:
1 # useradd -s /sbin/nologin mysql
安装cmake
1 # tar zxf cmake-2.8.12.2.tar.gz2 # cd cmake-2.8.12.2
3 # ./bootstrap --prefix=/usr/local/cmake4 # make && make install
5
6 # echo 'export PATH=$PATH:/usr/local/cmake/bin' >> /etc/profile7 # source /etc/profile
下载Boost源码
根据官方文档提示,此过程比较消耗内存,同时也一定注意,从MySQL5.7版本开始,安装MySQL需要依赖 Boost 的C++扩展,而且只能是 1.59.0 版本;
Boost 下载地址: http://www.boost.org/users/history ;选择1.59.0版本下载,在编译是填写相应参数,指定Boost源码位置即可;
# wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
# tar zxf boost_1_59_0.tar.gz
#mv boost_1_59_0 /usr/local/boots
编译安装mysql
# cd mysql-5.7.17# bpath='/opt/mysql/mysql_5717'# cmake . \-DCMAKE_INSTALL_PREFIX=${bpath} \-DINSTALL_MYSQLDATADIR="${bpath}/var"\-DMYSQL_DATADIR=${bpath}/var \-DSYSCONFDIR=${bpath}/etc \-DWITH_INNOBASE_STORAGE_ENGINE=1\-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DMYSQL_TCP_PORT=$bport \-DMYSQL_UNIX_ADDR=${bpath}/tmp/mysql.sock \-DWITH_EXTRA_CHARSETS=all \-DWITH_BOOST=/usr/local/boots \-DDOWNLOAD_BOOST=1#make && make install# cd/opt/mysql/mysql_5717/
# mkdir {etc,log,tmp,var}
# chown mysql.mysql -R *
配置文件
1 [mysql]2 port=3306
3 default_character_set=utf84 no_auto_rehash5
6 [client]7 port = 3306
8 socket = /opt/mysql/mysql_5717/tmp/mysql.sock9 loose_default_character_set =utf810
11 [mysqld]12 ####dir
13 pid-file = /opt/mysql/mysql_5717/tmp/mysql.pid14 socket = /opt/mysql/mysql_5717/tmp/mysql.sock15 datadir = /opt/mysql/mysql_5717/data16 tmpdir = /tmp17
18 ####server19 server_id = 503306
20 port=3306
21 max_connections=3000
22 max_user_connections=1000
23 character_set_server=utf824 default_time_zone = '+08:00'
25 secure_file_priv =NULL26 sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
27 log_timestamps=system28 transaction_write_set_extraction=MURMUR3229 show_compatibility_56=on30
31 default_storage_engine=INNODB32 lower_case_table_names=1
33 auto_increment_increment = 1
34 auto_increment_offset = 1
35 log_bin_trust_function_creators=1
36 explicit_defaults_for_timestamp=1
37
38 skip_external_locking39 skip_name_resolve40 wait_timeout=180
41 interactive_timeout=180
42 max_connect_errors=1000
43 open_files_limit=65535
44 connect_timeout=8
45 net_read_timeout=30
46 net_write_timeout=60
47 back_log=500
48
49 ####slow log50 long_query_time=1
51 slow_query_log=1
52 log_queries_not_using_indexes = 1
53 log_throttle_queries_not_using_indexes = 10
54 log_slow_admin_statements = 1
55 log_slow_slave_statements = 1
56 slow_query_log_file=/opt/mysql/mysql_5717/log/slowquery.log57
58 ####general log59 general_log=0
60 general_log_file=/opt/mysql/mysql_5717/log/general.log61
62 ####error log
63 log_error=/opt/mysql/mysql_5717/log/mysql.err64
65 ####query cache66 query_cache_type=0
67 query_cache_size=0
68 query_cache_limit=2M69 query_cache_min_res_unit=1K70
71 table_open_cache = 65536
72 max_allowed_packet=32M73 max_heap_table_size =100M74 tmp_table_size =64M75 thread_stack=512K76 thread_cache_size=1024
77 read_rnd_buffer_size =32M78 sort_buffer_size =32M79 read_buffer_size =32M80 join_buffer_size =128M81
82 ####innodb83 innodb_data_home_dir=/opt/mysql/mysql_5717/data84 innodb_log_group_home_dir=/opt/mysql/mysql_5717/data85 innodb_data_file_path=ibdata1:2G;ibdata2:16M:autoextend86 innodb_buffer_pool_size=4G87 innodb_buffer_pool_instances=4
88 innodb_log_files_in_group=2
89 innodb_log_file_size=1024M90 innodb_log_buffer_size=10M91 innodb_flush_log_at_trx_commit=2
92 innodb_max_dirty_pages_pct=60
93 innodb_thread_concurrency=32
94 innodb_read_io_threads=8
95 innodb_write_io_threads=8
96 innodb_open_files=60000
97 innodb_file_per_table=1
98 innodb_flush_method=O_DIRECT99 innodb_support_xa = 1
100 innodb_lock_wait_timeout=10
101 innodb_page_size = 8192
102 innodb_buffer_pool_load_at_startup = 1
103 innodb_buffer_pool_dump_at_shutdown = 1
104 innodb_buffer_pool_dump_pct = 40
105 innodb_page_cleaners = 4
106 innodb_lock_wait_timeout = 5
107 innodb_undo_directory = /opt/mysql/mysql_5717/data/
108 innodb_undo_logs = 128
109 innodb_undo_tablespaces = 3
110 innodb_undo_log_truncate = 1
111 innodb_max_undo_log_size =2G112 innodb_purge_rseg_truncate_frequency = 128
113 innodb_flush_neighbors = 1
114
115 ####myisam116 key_buffer_size =64M117 myisam_sort_buffer_size=64M118
119 ####gtid120 gtid_mode=off121 enforce_gtid_consistency=1
122
123 ####binlog124 log_bin = mysql-bin125 binlog_cache_size=4M126 max_binlog_cache_size=2G127 max_binlog_size=500M128 binlog_format=ROW129 #binlog_row_image=full130 sync_binlog=1
131 log_slave_updates=1
132 expire_logs_days=60
133
134 ####replication135 relay_log_recovery=1
136 relay_log_purge = 1
137 relay_log=relaylog138 read_only = 1
139 skip_slave_start140 slave_net_timeout=30
141 #slave_parallel_workers = 4
142 #master_info_repository =TABLE143 #relay_log_info_repository =TABLE144 #binlog_gtid_simple_recovery = 1
145 #slave_skip_errors =ddl_exist_errors146
147 [mysqldump]148 quick149 max_allowed_packet =32M150
151 [myisamchk]152 key_buffer_size =256M153 sort_buffer_size =256M154 read_buffer =2M155 write_buffer =2M156
157 [mysqlhotcopy]158 interactive_timeout
my.cnf
附上my.cnf,此文件存在$bpath/etc/下.
因此要把/etc/my.cnf删除.否则默认读/etc/my.cnf
配置文件中的参数不是通用.需要配合环境调整.
初始化mysql,mysql的初始密码存在mysql.err里
1 创建安装目录和数据存放目录,并修改权限2 # bin/mysqld --defaults-file=etc/my.cnf --initialize --user=mysql3 # cat /opt/mysql/mysql_5717/log/mysql.err |grep 'A temporary password'
4 2017-03-28T15:38:58.385432+08:00 1 [Note] A temporary password is generated for root@localhost: /0sgQgr3ADg*
5
6 这个是临时密码..一定要记住.
启动mysql
1 cd $bpath2 cp support-files/mysql.server /etc/init.d/mysqld3 ./bin/mysql.server restart4
5 也可以把mysql.server拷贝到/etc/init.d下 使用service来启动6 cp support-files/mysql.server /etc/init.d/mysqld7 /etc/init.d/mysqld start
登录并修改密码:
1 # ./bin/mysql -u root -p2
3 修改root密码,否则无法操作4 mysql> ALTER USER root@localhost IDENTIFIED BY ''123456";