[root@localhost ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison
[root@localhost ~]# wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[root@localhost ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz
也可以使用官方下载链接 进行下载。
[root@localhost ~]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
[root@localhost ~]# tar -zxvf boost_1_59_0.tar.gz
[root@localhost data]# md5sum mysql-5.7.13.tar.gz
8fab75dbcafcd1374d07796bff88ae00 mysql-5.7.13.tar.gz
[root@localhost ~]# tar -zxvf mysql-5.7.13.tar.gz
[root@localhost data]# mkdir -p /data/mysql
[root@localhost data]# cd mysql-5.7.13
[root@localhost data]# mkdir build
[root@localhost data]# cd build
[root@localhost data]# cmake ../ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DWITH_BOOST=../../boost_1_59_0 \
-DSYSCONFDIR=/etc \
-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=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1
[root@localhost mysql-5.7.13]# make -j `grep processor /proc/cpuinfo | wc -l`
#编译很消耗系统资源,小内存可能编译通不过make install
[root@localhost mysql-5.7.13]# make install
[root@localhost mysql-5.7.13]# ls -lrt /usr/local/mysql
[root@localhost mysql-5.7.13]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.7.13]# chmod +x /etc/init.d/mysqld
[root@localhost mysql-5.7.13]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on
/etc/my.cnf,仅供参考
[root@localhost mysql-5.7.13]# cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /dev/shm/mysql.sock
[mysqld]
port = 3306
socket = /dev/shm/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF
[root@localhost mysql-5.7.13]# echo -e '\n\nexport PATH=/usr/local/mysql/bin:$PATH\n' >> /etc/profile && source /etc/profile
[root@localhost mysql-5.7.13]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
注:
1 、MySQL之前版本mysql_install_db是在mysql_basedir/script下
2、MySQL 5.7直接放在了mysql_install_db/bin目录下。
3、"–initialize"已废弃,生成一个随机密码(~/.mysql_secret)
4、"–initialize-insecure"不会生成密码
5、"–datadir"目录下不能有数据文件
[root@localhost mysql-5.7.13]# systemctl start mysqld
[root@localhost mysql-5.7.13]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: active (running) since Mon 2018-09-03 15:37:30 CST; 20min ago
Docs: man:systemd-sysv-generator(8)
Process: 106256 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
Tasks: 27
Memory: 49.9M
CGroup: /system.slice/mysqld.service
├─106269 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
└─107105 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql-error.log --open...
Sep 03 15:37:28 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL...
Sep 03 15:37:30 localhost.localdomain mysqld[106256]: Starting MySQL.. SUCCESS!
Sep 03 15:37:30 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.
[root@localhost mysql-5.7.13]# ps -ef | grep mysql
root 23940 1 0 11:15 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql 24776 23940 0 11:15 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql-error.log --open-files-limit=65535 --pid-file=/data/mysql/mysql.pid --socket=/dev/shm/mysql.sock --port=3306
[root@localhost mysql-5.7.13]# netstat -tunpl | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 24776/mysqld
MySQL和Oracle数据库一样,数据库也默认自带了一个 root 用户(这个和当前Linux主机上的root用户是完全不搭边的),我们在设置好MySQL数据库的安全配置后初始化root用户的密码。配制过程中,一路输入 y 就行了。这里只说明下MySQL5.7.13版本中,用户密码策略分成低级 LOW 、中等 MEDIUM 和超强 STRONG 三种,推荐使用中等 MEDIUM 级别!
[root@localhost mysql-5.7.13]# mysql_secure_installation
一般MySQL数据库还会被类似于PHP等服务调用,所以我们需要将MySQL编译后的lib库文件添加至当前Linux主机链接库 /etc/ld.so.conf.d/
下,这样MySQL服务就可以被其它服务调用了。
[root@localhost mysql-5.7.13]# ldconfig |grep mysql
[root@localhost mysql-5.7.13]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql-5.7.13]# ldconfig
[root@localhost mysql-5.7.13]# ldconfig -v |grep mysql
ldconfig: 无法对 /libx32 进行 stat 操作: 没有那个文件或目录
ldconfig: 多次给出路径“/usr/lib”
ldconfig: 多次给出路径“/usr/lib64”
ldconfig: 无法对 /usr/libx32 进行 stat 操作: 没有那个文件或目录
/usr/lib64/mysql:
libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
/usr/local/mysql/lib:
libmysqlclient.so.20 -> libmysqlclient.so.20.3.0
[root@localhost mysql-5.7.13]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13-log Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>