二进制安装mysql5.7

时间:2021-11-03 19:47:59

1、创建用户和组

groupadd mysql

useradd -r -g mysql mysql

 

2、上传二进制包至/usr/local下解压并改名为mysql

tar zxvf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.7.12-linux-glibc2.5-x86_64  /usr/local/mysql

 

3、创建数据目录和日志目录并给予他们mysql:mysql权限

chown -R mysql:mysql /usr/local/mysql

mkdir -p /mysql/data

mkdir -p /mysql/log

chown -R mysql:mysql /mysql

 

4、把配置文件cp/etc下改名为my.cnf

cd /usr/local/mysql/support-files

cp my-default.cnf  /etc/my.cnf

 

5、修改配置文件

vi /etc/my.cnf

#GTID

server-id=1

report-host=192.168.87.1

port=3306

gtid-mode=on

enforce-gtid-consistency=true

log-slave-updates=true

master-info-repository=TABLE

relay-log-info-repository=TABLE

sync-master-info=1

binlog_cache_size=4M

max_binlog_size=1G

max_binlog_cache_size=512M

binlog-checksum=CRC32

binlog-rows-query-log_events=1

master-verify-checksum=1

slave_allow_batching=1

slave-sql-verify-checksum=1

slave-parallel-workers=4

relay_log_purge=1

relay_log_recovery=1

 

#InnoDB

innodb_buffer_pool_size=1G

innodb_io_capacity=2000

innodb_io_capacity_max=6000

innodb_lru_scan_depth=2000

 

#MyISAM

key_buffer_size=64M

myisam_sort_buffer_size=64M

concurrent_insert=2

delayed_insert_timeout=300

 

#Other

max-connect-errors=100000

max-connections=1200

max_allowed_packet=50M

 

lower_case_table_names=1

 

datadir=/mysql/data

 

log-error=/mysql/log/error.log

 

#binlog

binlog-format=ROW

binlog-row-image=minimal

log-bin=/mysql/log/mysql-bin.log

 

#slow log

slow_query_log=on

long_query_time=1

slow_query_log_file=/mysql/log/slow-query.log

---------------------

注意更改:

innodb_buffer_pool_size=1G

后面的值最好设置为内存的一半

report-host=192.168.1.127

IP换为本机的IP

server-id=1

配置主从的时候两台机器的不可以一样

-------------------------------

 

6、设置环境变量

vi /etc/profile

#by jlma

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

使环境变量生效:

source /etc/profile

 

7、初始化数据库

/usr/local/mysql/scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql --datadir=/mysql/data                          # Before MySQL 5.7.6

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --bas

edir=/usr/local/mysql --datadir=/mysql/data                           # MySQL 5.7.6 and up

如果是--initialize-insecure,则会创建空密码的root@localhost账号

如果是--initialize,则会自动生成密码的root@localhost账号

从初始化日志中获取root用户初始密码:

2016-04-14T19:30:12.877492Z 1 [Note] A temporary password is generated for root@localhost: r5sPW7wH*Yai

 

8、启动mysql

mysql_ssl_rsa_setup               # MySQL 5.7.6 and up

 

mysqld_safe --user=mysql &

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

service mysqld start

 

9、进入mysql中先把密码改成自己的密码

mysql

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

 

 

 

 

创建用户以及授权用户

 

grant all privileges on *.* to 'useradd'@'ip地址' IDENTIFIED BY 'passwd';