文章目录[隐藏]
今天测试在sentos7.2上安装MySQL5.7数据库,注意一centos的版本,和搭建流程。
一、查看确认centos的版本
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
二、安装依赖包和开发工具:
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++-33
三、清除系统中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-5.7.11.tar.gz -C /usr/src cd /usr/src/mysql-5.7.11 cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/home/mysql/data \ -DMYSQL_UNIX_ADDR=/home/mysql/pid/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DMYSQL_USER=mysql \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_READLINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLED_LOCAL_INFILE=1 \ -DENABLE_DOWNLOADS=1 \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=/usr/local/include/boost make && make install
七、编辑my.cnf配置文件:
cp /usr/src/mysql-5.7.11/support-files/my-default.cnf /etc/my.cnf vim /etc/my.cnf
[client] port = 3306 socket = /home/mysql/pid/mysql.sock default-character-set = utf8 [mysql] prompt="MySQL [\d]> " no-auto-rehash default-character-set = utf8 [mysqld] port = 3306 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 = 1 init-connect = 'SET NAMES utf8' character-set-server = utf8 skip-name-resolve skip-external-locking back_log = 300 lower_case_table_names = 1 ft_min_word_len = 1 performance_schema = 0 explicit_defaults_for_timestamp=true max_connections = 3896 max_connect_errors = 6000 open_files_limit = 65535 table_open_cache = 1024 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 = 64 query_cache_type = 1 query_cache_size = 256M query_cache_limit = 2M #log_bin = /home/mysql/log/mysql-bin binlog_format = mixed expire_logs_days = 7 log_error = /home/mysql/log/mysql_error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /home/mysql/log/mysql-slow.log default_storage_engine = InnoDB #default-storage-engine = MyISAM innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 1024M 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 = 64M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 [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-5.7.11/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig --add mysqld chkconfig --level 2345 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 3306
十三、 登录并修改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