MySQL是一款关系数据库管理系统,原开发者为瑞典MySQL AB公司,目前已属于Oracle公司产品之一。MySQL因性能高、成本低、可靠性好,已经成为最流行的开源数据库,广受个人建站爱好者青睐。
安装MySQL环境
操作系统:CentOS 7.7
MySQL:5.7.28
MySQL安装篇
第一步 安装依赖包
[root@wanghualang ~]# yum -y install wget vim make cmake gcc gcc-c++ openssl-devel bison-devel ncurses-devel
第二步 下载、解压源码包
[root@wanghualang ~]# cd /usr/local/src/ [root@wanghualang src]# wget --no-check-certificate https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz [root@wanghualang src]# tar xzf mysql-boost-5.7.28.tar.gz
第三步 新建用户组、用户
[root@wanghualang ~]# groupadd mysql [root@wanghualang ~]# useradd mysql -M -g mysql -s /sbin/nologin
第四步 编译安装MySQL(按需添加更多功能模块)
[root@wanghualang ~]# cd /usr/local/src/mysql-5.7.28 [root@wanghualang mysql-5.7.28]# cmake / -DCMAKE_INSTALL_PREFIX=/usr/local/mysql / -DSYSCONFDIR=/etc / -DMYSQL_TCP_PORT=3306 / -DEXTRA_CHARSETS=all / -DDEFAULT_CHARSET=utf8mb4 / -DDEFAULT_COLLATION=utf8mb4_general_ci / -DWITH_MYISAM_STORAGE_ENGINE=1 / -DWITH_INNOBASE_STORAGE_ENGINE=1 / -DWITH_PARTITION_STORAGE_ENGINE=1 / -DWITH_FEDERATED_STORAGE_ENGINE=1 / -DWITH_EMBEDDED_SERVER=1 / -DENABLED_LOCAL_INFILE=1 / -DWITH_BOOST=/usr/local/src/mysql-5.7.28/boost/boost_1_59_0 [root@wanghualang mysql-5.7.28]# make [root@wanghualang mysql-5.7.28]# make install
第五步 优化数据库配置(4G内存优化方案,仅供参考)
[root@wanghualang ~]# vim /etc/my.cnf
把如下代码输入
[client] port=3306 socket=/tmp/mysql.sock [mysqld] #bind_address=127.0.0.1 binlog_cache_size=128K thread_stack=256K join_buffer_size=2048K query_cache_type=1 max_heap_table_size=512M port=3306 pid-file=/tmp/mysql.pid socket=/tmp/mysql.sock datadir=/usr/local/mysql/data skip-external-locking performance_schema_max_table_instances=400 table_definition_cache=400 key_buffer_size=384M max_allowed_packet=100G table_open_cache=384 sort_buffer_size=1024K net_buffer_length=8K read_buffer_size=1024K read_rnd_buffer_size=768K myisam_sort_buffer_size=16M thread_cache_size=128 query_cache_size=192M tmp_table_size=512M sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp=true #skip-networking max_connections=300 max_connect_errors=100 open_files_limit=65535 #log-bin=mysql-bin #binlog_format=mixed server-id=1 expire_logs_days=10 slow_query_log=1 slow-query-log-file=/usr/local/mysql/data/mysql-slow.log long_query_time=3 #log_queries_not_using_indexes=on early-plugin-load="" default_storage_engine=InnoDB innodb_data_home_dir=/usr/local/mysql/data innodb_data_file_path=ibdata1:10M:autoextend innodb_log_group_home_dir=/usr/local/mysql/data innodb_buffer_pool_size=512M innodb_log_file_size=128M innodb_log_buffer_size=32M innodb_flush_log_at_trx_commit=1 innodb_lock_wait_timeout=120 innodb_max_dirty_pages_pct=90 innodb_read_io_threads=2 innodb_write_io_threads=2 [mysqldump] quick max_allowed_packet=16M [mysql] no-auto-rehash [myisamchk] key_buffer_size=64M sort_buffer_size=1M read_buffer=2M write_buffer=2M [mysqlhotcopy] interactive-timeout
第六步 修改数据库目录、配置文件权限
[root@wanghualang ~]# chown mysql:mysql /etc/my.cnf [root@wanghualang ~]# chown -R mysql:mysql /usr/local/mysql
第七步 配置数据库环境变量
[root@wanghualang ~]# echo "export PATH="/usr/local/mysql/bin:$PATH"" >> /etc/profile [root@wanghualang ~]# source /etc/profile
第八步 配置启动服务脚本、开机启动
[root@wanghualang ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@wanghualang ~]# chmod +x /etc/init.d/mysqld [root@wanghualang ~]# chkconfig --add mysqld [root@wanghualang ~]# chkconfig mysqld on
第九步 初始化数据库
[root@wanghualang ~]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
第十步 测试启动
[root@wanghualang ~]# service mysqld start [root@wanghualang ~]# mysql
官方QQ群号码:922069959(空)、1093596563(空)