靳闯博客 记录是一种习惯,分享是一种态度
  • 波浪
  • 波浪
  • 波浪
  • 波浪
mysql5.7 安装配置
发表于: | 分类: 技术积累 | 标签: linux mysql | 评论:0 | 阅读: 223

1 安装好开发环境各种依赖包

yum groupinstall "Development tools"

2 安装依赖包

yum search libaio # search for info
yum install libaio # install library

3 新建用户组和用户

groupadd mysql
useradd mysql -g mysql

4 建立存放数据库目录

mkdir /data

5 解压包指定目录

wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18.tar.gz
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-i686.tar.gz
#大小625M mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 这里使用官网编译好的二进制安装包
tar xf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /data
mv mysql-5.7.18-linux-glibc2.5-x86_64 mysql5.7

6 安装

#创建data目录
mkdir -p /data/mysql/data

#更改所有者
chown -R mysql:mysql /data/

#初始化数据库
/data/mysql/bin/mysqld --user=mysql --basedir=/data/mysql/ --datadir=/data/mysql/data --initialize
初始化后记下mysql root用户随机产生的密码 pychBtXfV3-A #见底部图片样例#

![mysql5.7 init][1]
#拷贝启动程序文件到/etc/init.d/下面
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

#修改启动脚本文件
vim /etc/init.d/mysqld
修改mysql程序路径 为我们自定义的路径
basedir=/data/mysql
datadir=/data/mysql/data

#先清理一下内存
sync
echo 3 > /proc/sys/vm/drop_caches

#配置my.cnf
vim /etc/my.cnf

[client]
#no-beep
socket =/data/mysql/mysql.sock
# pipe
# socket=0.i0
port=3306
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4

[mysqld]
basedir=/data/mysql
datadir=/data/mysql/data
port=7416
pid-file=/data/mysql/mysqld.pid
bind-address=0.0.0.0
#skip-grant-tables
skip-name-resolve
socket = /data/mysql/mysql.sock
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true

#字符集
character-set-client-handshake = FALSE
character_set_filesystem = utf8mb4
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect = 'SET NAMES utf8mb4'
skip-character-set-client-handshake = true

# Server Id
server-id=1
log-bin = mysql-bin
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300

#logs 初始化的时候如果配置好了log,那么随机密码相关信息会写入logs中不会前台打印
general_log = ON
general_log_file = /data/mysql/logs/mysql.log
log_error = /data/mysql/logs/mysql-error.log
#slow_query_log = on
#slow-query-log-file = /data/mysql5.7/logs/slow-query.log
#long_query_time = 2

#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /data/mysql/data
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=256M
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 = 28800
wait_timeout = 28800
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_DATE

7启动mysql

service mysqld start

8增加环境变量

vim /etc/profile
最下面加上:
export PATH=${PATH}:/data/mysql/bin

#使环境变量生效
source /etc/profile  或者 . /etc/profile

9修改root密码

mysql –uroot –p
【密码为初始化数据库时给出的随机密码】

#修改密码,不然无法执行mysql相关命令操作
mysql>SET PASSWORD = PASSWORD('root');

mysql_init



如果这篇文章帮助到了你,我感到十分荣幸!

或许你不想写点什么......

icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif

站点地图 网站地图
豫ICP备17003270号 | Copyright © 2017-2018 💖 靳闯博客
Typecho🍹Sgreen
TOP