首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Mysql 5.7 二进制安装

引言

大家好,我是应用DBA的菓琭,这是我发表的第一编小白文《myql 5.7 二进制安装》,够直白了吧!就是安装mysql,想学mysql首先要安装啊,要不怎么玩~接下来我们进入正题。

说明

mysql有三种安装方式:

rpm包,安装极其简单,但是无法升级,应用场景不多

二进制,安装快、简单,方便移植,可升级

源码,安装较慢,自定义强,可升级

蓝色斜字体需要根据各环境修改

1.到官网下载二进制包(解压就可以用),并卸载操作系统自带的mysql

https://dev.mysql.com/downloads/mysql/

操作系统: Linux-Generic

OSVersion: x86,64-bit

mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

# rpm -qa |grep mysql

mysql-libs-5.1.71-1.el6.x86_64

# rpm -e --nodepsmysql-libs-5.1.71-1.el6.x86_64

2.解压至/usr/local/mysql路径下(想区分版本就带版本号)

# tar -zxvfmysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

# mvmysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql

# cd /usr/local/mysql

# ls

binCOPYING docs include lib man README share support-files

3.创建mysql用户,且配置root与mysql的环境变量

# groupadd mysql

# useradd -g mysql -d/home/mysql mysql

# passwd mysql

# vi .bash_profile

exportPATH=$PATH:/usr/local/mysql/bin

4.创建目录(标准),并授权至mysql用户

# mkdir -p /app/mysqldata

# mkdir -p /app/mysqllog

# mkdir -p/app/mysqlbinlog

# mkdir -p/app/mysqlrelaylog

# chown -R mysql:mysql/app/mysql*

5.修改/etc/my.cnf配置(5.7):

# vi /etc/my.cnf

[client]

socket= /app/mysqldata/mysql.sock

port =3306

host=localhost

user=root

password=

[mysql]

no-auto-rehash

[mysqld]

#############GENERAL #############

autocommit= ON

character_set_server= utf8mb4

collation-server= utf8mb4_general_ci

lower_case_table_names= 1

port =3306

transaction_isolation= REPEATABLE-READ

tmp_table_size=32M

max_heap_table_size=32M

###############PATH ##############

tmpdir= /app/mysqldata/

datadir= /app/mysqldata/

socket= /app/mysqldata/mysql.sock

log_error= /app/mysqllog/error.log

general_log_file= /app/mysqllog/general.log

slow_query_log_file= /app/mysqllog/slow.log

log_bin= /app/mysqlbinlog/mysql-bin

log_bin_index= /app/mysqlbinlog/mysql-bin.index

relay_log= /app/mysqlrelaylog/mysql-relay

relay_log_index= /app/mysqlrelaylog/mysql-relay.index

#######CACHES AND LIMITS #########

max_allowed_packet= 32M

max_connect_errors= 10000

max_connections= 1000

wait_timeout= 28800

slave_net_timeout= 100

#interactive_timeout= 100

sort_buffer_size= 1M

table_open_cache= 4000 ###SHOW GLOBAL STATUS-->Open_tables

table_open_cache_instances= 4

#############SAFETY ##############

log_bin_trust_function_creators= true

skip_name_resolve= ON

#skip_grant_table

#############LOGGING #############

general_log= OFF

#log_queries_not_using_indexes= ON

log_queries_not_using_indexes= OFF

log_slow_admin_statements= ON

long_query_time= 5

slow_query_log= ON

#############INNODB #############

innodb_flush_method= O_DIRECT

innodb_buffer_pool_size= 12288M

innodb_log_file_size= 512M

innodb_log_files_in_group= 3

innodb_log_buffer_size= 16M

innodb_read_io_threads= 8

innodb_write_io_threads= 8

innodb_strict_mode= ON

#innodb_data_file_path= ibdata1:256M;ibdata2:16M:autoextend

innodb_io_capacity= 2000

innodb_lock_wait_timeout= 50

innodb_open_files= 16384

innodb_data_home_dir= /app/mysqldata/

binlog_format= 'ROW'

innodb_log_group_home_dir= /app/mysqldata/

innodb_thread_concurrency= 48

#############MyISAM #############

key_buffer_size= 500M

myisam_sort_buffer_size= 64M

thread_cache_size= 100

#############REPLICATION #############

binlog_format= ROW

expire_logs_days= 7

max_binlog_size= 512M

server_id= 108

innodb_flush_log_at_trx_commit= 2

sync_binlog= 100

log_slave_updates= ON

6.初始化mysql数据库

$/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize--user=mysql --log_error_verbosity --explicit_defaults_for_timestamp

7.配置service启动mysql

#/usr/local/mysqlbin/mysqld_safe --defaults-file=/etc/my.cnf &

启动方法二

# cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

# service mysql start

关闭mysql

# mysqladmin -uroot -pshutdown

8. 修改Mysql的root用户密码以及打开远程连接

临时密码在/app/mysqllog/error.log里面

2018-03-07T13:15:45.279798Z1 [Note] A temporary password is generated for root@localhost: /8aJqrwI4PiV

# mysql -uroot-p/8aJqrwI4PiV

mysql > alter user 'root'@'localhost'identified by 'password';

mysql > GRANT ALLPRIVILEGES ON *.* TO 'root'@'%' identified by 'password'WITH GRANT OPTION;

mysql > GRANT PROXY ON''@'' TO 'root'@'%' WITH GRANT OPTION;

mysql >flushprivileges;

9. 创建客户数据库与用户yy授权

mysql > createdatabaseyydefault character set utf8mb4 collate utf8mb4_general_ci;

mysql > grantselect,insert,update,delete,create,alter,drop,index,create view,showview,create routine,alter routine,execute onyy.* to 'yy'@'%' identifiedby 'password' ;

结束完美撒花~

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180626G0S62500?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券