mysql 5.7二进制包安装

时间:2021-07-15 00:42:40

1.上传安装安装包mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz到/home/mysqlintall目录并解压

2.建立用户mysql和组

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

3.创建连接到/usr/local/mysql

ln -s /home/mysqlinstall/mysql-5.7.14-linux-glibc2.5-x86_64 mysql

4.修改用户属组和属主

[root@mysqlslave mysql]# chown -R mysql .
[root@mysqlslave mysql]# chgrp -R mysql .

5.整理mysql配置文件my.cnf

[root@mysqlmaster support-files]# cat /etc/my.cnf 

# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
# Configuration name mysqlmaster generated for jackwangw@126.com at 2017-06-19 09:31:40
[mysql]

# CLIENT #
port                           = 3306
socket                         = /mysqldata/mysql.sock
[mysqld]
# GENERAL #
user                           = mysql
default-storage-engine         = InnoDB
socket                         = /mysqldata/mysql.sock
pid-file                       = /mysqldata/mysql.pid

# MyISAM #
key-buffer-size                = 32M
#myisam-recover                 = FORCE,BACKUP

# SAFETY #
max-allowed-packet             = 16M
max-connect-errors             = 1000000
skip-name-resolve
sql-mode                       = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
sysdate-is-now                 = 1

# DATA STORAGE #
datadir                        = /mysqldata/data

# BINARY LOGGING #
server-id                       = 1
log-bin                        = /mysqldata/mysql-bin
expire-logs-days               = 14
sync-binlog                    = 1

# REPLICATION #
skip-slave-start               = 1
log-slave-updates              = 1
relay-log                      = /mysqldata/relay-bin
slave-net-timeout              = 60

# CACHES AND LIMITS #
tmp-table-size                 = 32M
max-heap-table-size            = 32M
query-cache-type               = 0
query-cache-size               = 0
max-connections                = 500
thread-cache-size              = 50
open-files-limit               = 65535
table-definition-cache         = 1024
table-open-cache               = 100

# INNODB #
innodb-flush-method            = O_DIRECT
innodb-log-files-in-group      = 2
innodb-log-file-size           = 64M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table          = 1
innodb-buffer-pool-size        = 800M

# LOGGING #
log-error                      = /mysqldata/mysql-error.log
log-queries-not-using-indexes  = 1
slow-query-log                 = 1

slow-query-log-file            = /mysqldata/mysql-slow.log

6.初始化mysql

mysqld --initialize --user=mysql

7.启动验证mysql

[root@mysqlmaster bin]# mysqld_safe --user=mysql 
2017-06-20T03:32:06.621381Z mysqld_safe Logging to '/mysqldata/mysql-error.log'.
2017-06-20T03:32:06.645907Z mysqld_safe Starting mysqld daemon with databases from /mysqldata/data

7.配置mysql作为服务启动

[root@mysqlmaster support-files]# cp mysql.server /etc/init.d/mysqld
[root@mysqlmaster support-files]# chmod 755 /etc/init.d/mysqld 
[root@mysqlmaster support-files]# chkconfig --add mysqld
[root@mysqlmaster support-files]# service mysqld status
MySQL running (29666)                                      [纭甝
[root@mysqlmaster support-files]# service mysqld stop
Shutting down MySQL..                                      [纭甝

8.遇到问题

2017-06-20T03:25:05.274986Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
2017-06-20T03:25:05.275227Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

2017-06-20T03:25:05.389533Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2017-06-20T03:25:05.389604Z 0 [ERROR] Aborting

解决配置中datadir                        = /mysqldata/    改为datadir                        = /mysqldata/data 重新初始化问题解决


mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> show databases
    -> ;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'root001';
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.10 sec)