一、安装依赖包和开发工具:
yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf python-devel zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* libicu-devel libxslt-devel postgresql-devel curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-
二、清除系统中mysql痕迹:
yum remove mysql rm -f /etc/my.cnf
三、创建mysql用户和用户组:
groupadd mysql useradd -s /sbin/nologin -M -g mysql mysql
四、安装boost:
tar zxvf boost_1_60_0.tar.gz -C /usr/src cd /usr/src/boost_1_60_0 ./bootstrap.sh ./b2 --prefix=/usr/local ./b2 install
五、解压、配置、编译、安装mysql_5.7:
tar zxvf mysql-.tar.gz -C /usr/src cd /usr/src/mysql- cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/home/mysql/data \ -DMYSQL_UNIX_ADDR=/home/mysql/pid/mysql.sock \ -DMYSQL_TCP_PORT= \ -DMYSQL_USER=mysql \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_READLINE= \ -DWITH_MYISAM_STORAGE_ENGINE= \ -DWITH_INNOBASE_STORAGE_ENGINE= \ -DWITH_ARCHIVE_STORAGE_ENGINE= \ -DWITH_BLACKHOLE_STORAGE_ENGINE= \ -DWITH_MEMORY_STORAGE_ENGINE= \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DWITH_EMBEDDED_SERVER= \ -DENABLED_LOCAL_INFILE= \ -DENABLE_DOWNLOADS= \ -DDOWNLOAD_BOOST= \ -DWITH_BOOST=/usr/local/include/boost make && make install
六、编辑my.cnf配置文件:
cp /usr/src/mysql-/support-files/my-default.cnf /etc/my.cnf vim /etc/my.cnf
[client] port = socket = /home/mysql/pid/mysql.sock default-character-set = utf8 [mysql] prompt="MySQL [\d]> " no-auto-rehash default-character-set = utf8 [mysqld] port = socket = /home/mysql/pid/mysql.sock datadir = /home/mysql/data pid-file = /home/mysql/pid/mysqld.pid user = mysql bind-address = 0.0.0.0 server-id = init-connect = 'SET NAMES utf8' character-set-server = utf8 skip-name-resolve skip-external-locking back_log = lower_case_table_names = ft_min_word_len = performance_schema = explicit_defaults_for_timestamp=true max_connections = max_connect_errors = open_files_limit = table_open_cache = max_allowed_packet = 10M binlog_cache_size = 1M max_heap_table_size = 8M tmp_table_size = 128M read_buffer_size = 16M read_rnd_buffer_size = 32M sort_buffer_size = 16M join_buffer_size = 8M key_buffer_size = 256M thread_cache_size = query_cache_type = query_cache_size = 256M query_cache_limit = 2M #log_bin = /home/mysql/log/mysql-bin binlog_format = mixed expire_logs_days = log_error = /home/mysql/log/mysql_error.log slow_query_log = long_query_time = slow_query_log_file = /home/mysql/log/mysql-slow.log default_storage_engine = InnoDB #default-storage-engine = MyISAM innodb_file_per_table = innodb_open_files = innodb_buffer_pool_size = 1024M innodb_write_io_threads = innodb_read_io_threads = innodb_thread_concurrency = innodb_purge_threads = innodb_flush_log_at_trx_commit = innodb_log_buffer_size = 2M innodb_log_file_size = 32M innodb_log_files_in_group = innodb_max_dirty_pages_pct = innodb_lock_wait_timeout = bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 64M myisam_max_sort_file_size = 10G myisam_repair_threads = interactive_timeout = wait_timeout = [mysqldump] quick max_allowed_packet = 20M [myisamchk] key_buffer_size = 256M sort_buffer_size = 32M read_buffer = 16M write_buffer = 16M
七、修改目录权限、生成新的mysql授权表:
mkdir -p /home/mysql/log mkdir -p /home/mysql/data chown -R mysql:mysql /home/mysql/ /usr/local/mysql/bin/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --datadir=/home/mysql/data --basedir=/usr/local/mysql
八、添加mysqld系统服务:
cp /usr/src/mysql-/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig --level mysqld on chkconfig --list | grep mysqld
九、添加加载mysql库文件的路径:
echo /usr/local/mysql/lib >> /etc/ld.so.conf.d/mysql-x86_64.conf echo /usr/lib64/mysql >> /etc/ld.so.conf.d/mysql-x86_64.conf cp /etc/ld.so.conf.d/mysql-x86_64.conf /etc/ld.so.conf.d/mysql.conf ldconfig
十、链接可执行文件到系统环境变量:
ln -s /usr/local/mysql/lib/mysql /usr/lib64/mysql ln -s /usr/local/mysql/include/mysql /usr/include/mysql ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin
十一、启动mysql服务:
service mysqld start ps -aux | grep mysqld netstat -anptu | grep
十二、登录并修改mysql的root密码:
cat ~/.mysql_secret
# 查看mysql默认的初始密码
mysql -uroot -p
# 输入.mysql_secret文件内的初始密码
set password for root@localhost = password('Passw0rd!'); grant all privileges on *.* to root@'%' identified by 'Passw0rd!'; update mysql.user set Grant_priv='Y' where Host='%'; flush privileges; # "Passwrd!" 是修改的密码
十三、防火墙开启3306端口:
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT