重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
导读:
本文主要介绍 CentOS 系统二进制安装 MySQL 5.7.23 版本的安装步骤,其他版本安装过程相似。创新互联建站服务项目包括汕城网站建设、汕城网站制作、汕城网页制作以及汕城网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,汕城网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到汕城省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
卸载旧版MySQL
rpm -qa|grep mysql
若有可用rpm -e
卸载
find / -name mysql
安装相关依赖
yum -y install make gcc-c++ cmake bison-devel ncurses-devel numactl libaio
创建用户和用户组
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
cd /usr/local/
# wget下载或者本地下载后上传
wget https://downloads.mysql.com/archives/get/file/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 解压安装包
tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 解压后为了方便后面操作可把解压后文件名修改为mysql
mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql
# 更改文件夹所属
chown -R mysql.mysql /usr/local/mysql/
mkdir -p /data/mysql/{data,logs,tmp}
# 更改文件夹所属
chown -R mysql.mysql /data/mysql/
vi /etc/my.cnf
# 简单模板如下:
[client]
port = 3306
socket = /data/mysql/tmp/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/data
port = 3306
socket = /data/mysql/tmp/mysql.sock
pid-file = /data/mysql/tmp/mysqld.pid
tmpdir = /data/mysql/tmp
skip_name_resolve = 1
symbolic-links=0
max_connections = 2000
group_concat_max_len = 1024000
sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names = 1
log_timestamps=SYSTEM
character-set-server = utf8
interactive_timeout = 1800
wait_timeout = 1800
max_allowed_packet = 32M
binlog_cache_size = 4M
sort_buffer_size = 2M
read_buffer_size = 4M
join_buffer_size = 4M
tmp_table_size = 96M
max_heap_table_size = 96M
max_length_for_sort_data = 8096
#logs
server-id = 1003306
log-error = /data/mysql/logs/error.log
slow_query_log = 1
slow_query_log_file = /data/mysql/logs/slow.log
long_query_time = 3
log-bin = /data/mysql/logs/binlog
binlog_format = row
expire_logs_days = 15
log_bin_trust_function_creators = 1
relay-log = /data/mysql/logs/relay-bin
relay-log-recovery = 1
relay_log_purge = 1
#innodb
innodb_file_per_table = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_flush_method = O_DIRECT
innodb_autoinc_lock_mode = 2
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_buffer_pool_size = 2G
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql
# 修改目录位置
basedir=/usr/local/mysql
datadir=/data/mysql/data
# 注册开机启动服务
chkconfig --add mysql
chkconfig --list
echo "PATH=$PATH:/usr/local/mysql/bin " >> /etc/profile
source /etc/profile
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
# 临时密码保存在errlog中
# 获取临时密码
more /data/mysql/logs/error.log |grep password
# 启动mysql服务
service mysql start
# 使用初始密码登录mysql服务 并修改密码
mysql -uroot -p
alter user 'root'@'localhost' identified by 'root';
flush privileges;