在CentOS7系统上编译安装MySQL 5.7.13步骤详解
mysql 5.7主要特性
1、更好的性能
对于多核cpu、固态硬盘、锁有着更好的优化,每秒100w qps已不再是mysql的追求,下个版本能否上200w qps才是用户更关心的。
2、更好的innodb存储引擎
3、更为健壮的复制功能
复制带来了数据完全不丢失的方案,传统金融客户也可以选择使用。此外,gtid在线平滑升级也变得可能。
4、更好的优化器
优化器代码重构的意义将在这个版本及以后的版本中带来巨大的改进,oracle官方正在解决mysql之前最大的难题。
5、原生json类型的支持
6、更好的地理信息服务支持
innodb原生支持地理位置类型,支持geojson,geohash特性
7、新增sys库
以后这会是dba访问最频繁的库mysql 5.7已经作为数据库可选项添加到《oneinstack》
安装准备
安装依赖包
[root@snails ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison
下载相应源码包
[root@snails ~]# wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz [root@snails ~]# wget http://cdn.mysql.com/downloads/mysql-5.7/mysql-5.7.13.tar.gz
新建mysql用户和用户组
[root@snails ~]# groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -m mysql
预编译
[root@snails ~]# tar -zxvf boost_1_59_0.tar.gz [root@snails data]# md5sum mysql-5.7.13.tar.gz 8fab75dbcafcd1374d07796bff88ae00 mysql-5.7.13.tar.gz [root@snails ~]# tar -zxvf mysql-5.7.13.tar.gz [root@snails data]# mkdir -p /data/mysql [root@snails data]# cd mysql-5.7.13 [root@snails 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@snails mysql-5.7.13]# make -j `grep processor /proc/cpuinfo | wc -l` #编译很消耗系统资源,小内存可能编译通不过make install [root@snails mysql-5.7.13]# make install
设置启动脚本,开机自启动
[root@snails mysql-5.7.13]# ls -lrt /usr/local/mysql [root@snails mysql-5.7.13]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@snails mysql-5.7.13]# chmod +x /etc/init.d/mysqld [root@snails 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@snails 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
添加mysql的环境变量
[root@snails mysql-5.7.13]# echo -e '\n\nexport path=/usr/local/mysql/bin:$path\n' >> /etc/profile && source /etc/profile
初始化数据库
[root@snails mysql-5.7.13]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
注:
- mysql之前版本mysql_install_db是在mysql_basedir/script下
- mysql 5.7直接放在了mysql_install_db/bin目录下。
- "–initialize"已废弃,生成一个随机密码(~/.mysql_secret)
- "–initialize-insecure"不会生成密码
- "–datadir"目录下不能有数据文件
启动数据库
[root@snails mysql-5.7.13]# systemctl start mysqld [root@snails mysql-5.7.13]# systemctl status mysqld mysqld.service - lsb: start and stop mysql loaded: loaded (/etc/rc.d/init.d/mysqld) active: active (running) since 一 2016-07-18 11:15:35 cst; 8s ago docs: man:systemd-sysv-generator(8) process: 23927 execstart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/success) cgroup: /system.slice/mysqld.service ├─23940 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid └─24776 /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-err... 7月 18 11:15:32 snails systemd[1]: starting lsb: start and stop mysql... 7月 18 11:15:35 snails mysqld[23927]: starting mysql..[ ok ] 7月 18 11:15:35 snails systemd[1]: started lsb: start and stop mysql.
查看mysql服务进程和端口
[root@snails 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@snails mysql-5.7.13]# netstat -tunpl | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* listen 24776/mysqld
设置数据库root用户密码
mysql和oracle数据库一样,数据库也默认自带了一个 root 用户(这个和当前linux主机上的root用户是完全不搭边的),我们在设置好mysql数据库的安全配置后初始化root用户的密码。配制过程中,一路输入 y 就行了。这里只说明下mysql5.7.13版本中,用户密码策略分成低级 low 、中等 medium 和超强 strong 三种,推荐使用中等 medium 级别!
[root@snails mysql-5.7.13]# mysql_secure_installation
常用操作
将mysql数据库的动态链接库共享至系统链接库
一般mysql数据库还会被类似于php等服务调用,所以我们需要将mysql编译后的lib库文件添加至当前linux主机链接库 /etc/ld.so.conf.d/下,这样mysql服务就可以被其它服务调用了。
[root@snails mysql-5.7.13]# ldconfig |grep mysql [root@snails mysql-5.7.13]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf [root@snails mysql-5.7.13]# ldconfig [root@snails 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
创建其它mysql数据库用户
[root@snails 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>
mysql>create database `tonnydb` default character set utf8 collate utf8_general_ci; query ok, 1 row affected (0.01 sec) mysql> show databases; +--------------------+ | database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | tonnydb | +--------------------+ 5 rows in set (0.00 sec) mysql> grant all privileges on tonnydb.* to 'tonny@%' identified by 'hi.tonny@888'; query ok, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; query ok, 0 rows affected (0.01 sec) mysql> exit
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。