centos7安装mysql5.7
1、下载mysql
# 创建安装包目录
mkdir -p /data/src
cd /data/src
# 下载mysql
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.25.tar.gz
2、安装mysql
# 解压文件
tar xf mysql-boost-5.7.25.tar.gz
# 安装依赖
yum install -y gcc gcc-c++ cmake ncurses ncurses-devel bison
# 编译安装
cd mysql-5.7.25
cmake -DCMAKE_INSTALL_PREFIX=/data/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
# 无报错,执行编译
make
# 无报错,编译安装
make install
3、配置
# 创建mysql用户
useradd -s /sbin/nologin mysql
# 编辑mysql配置文件my.cnf
vim /etc/my.cnf
# 文件内容如下
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
user = mysql
basedir = /data/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/mysql.pid
log_error = /data/mysql/logs/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/logs/mysql-slow.log
#skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 1024M
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 8K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
query_cache_size = 16M
tmp_table_size = 32M
performance_schema_max_table_instances = 1000
explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log_bin=mysql-bin
binlog_format=mixed
server_id = 232
expire_logs_days = 10
early-plugin-load = ""
default_storage_engine = InnoDB
innodb_file_per_table = 1
#innodb_buffer_pool_size = 128M
innodb_log_file_size = 32M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M
# 切换到mysql安装目录
cd /data/mysql
# 创建日志目录
mkdir logs
# 目录授权mysql用户
chown -R mysql:mysql /data/mysql
# 初始化mysql
bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
# 拷贝启动文件
cp support-files/mysql.server /etc/init.d/mysqld
# 加执行权限
chmod +x /etc/init.d/mysqld
# 设置环境变量
vim /etc/profile
# 内容如下:
export PATH=$PATH:/data/mysql/bin
# 保存退出,环境变量生效
source /etc/profile
# 启动mysql
/etc/init.d/mysqld start
# 登陆mysql
mysql
# 设置root密码
update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
//添加服务
chkconfig --add mysqld
//显示服务列表
chkconfig --list
正文到此结束
评论
登录后才能发表评论 登录/注册
0评论