阿里云上面,安静环境安装mysql数据库,指定安装目录、指定数据文件 目录
linux系统版本: CentOS Linux release 7.4 64位
安装源文件版本:mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mysql安装路径:/apply/mysql
数据库文件数据位置:/data/mysql
安装步骤
1、在系统跟目下创建apply和data
# mkdir apply
# mkdir data
# mkdir mysql
2、上传mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz到apply文件夹下
3、在apply文件夹下解压JDK
# tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
4、重命名解压后JDK文件夹
# mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
5、创建mysql用户组和mysql用户
# groupadd mysql
# useradd -r -g mysql mysql
6、关联mysql用户到mysql用户组中
# chown -R mysql:mysql /apply/mysql/
# chown -R mysql:mysql /data/mysql/
# chown -R mysql /apply/mysql/
# chown -R mysql /data/mysql
7、更改mysql安装文件夹mysql/的权限
# chmod -R 755 /apply/mysql/
8、安装libaio依赖包
查询是否安装libaio依赖包(如果是阿里云或者腾讯云的基本都自带的有)
# yum search libaio
如果没有安装用yum命令安装
# yum install libaio
9、初始化mysql命令
# cd /apply/mysql/bin
# ./mysqld --user=mysql --basedir=/apply/mysql --datadir=/data/mysql --initialize
这里会报错:
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
是因为libnuma安装的是32位的,我们需要的则是64位
运行命令安装:
# yum install numactl.x86_64
再次执行初始化命令就OK了
如果还报这个错的话执行安装libaio就好了,命令↓
# yum install -y libaio
10、启动mysql服务
# sh /apply/mysql/support-files/mysql.server start
这个时候启动mysql服务的话会报错,如图↓
这是因为没有修改mysql配置文件造成的
11、修改mysql.servre配置文件
# vim /apply/mysql/support-files/mysql.server
修改前↓
修改后↓
if test -z "$basedir"
then
basedir=/apply/mysql
bindir=/apply/mysql/bin
if test -z "$datadir"
then
datadir=/data/mysql
fi
sbindir=/apply/mysql/bin
libexecdir=/apply/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
编辑好之后命令:wq!保存并退出
# cp /apply/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
12、修改my.cnf文件
# vim /etc/my.cnf
将下面内容替换当前的my.cnf文件内容
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
basedir=/apply/mysql
datadir=/data/mysql
port=3306
pid-file=/apply/mysql/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /apply/mysql/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /data/mysql
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
13、启动mysql