mysql5.7.21源码安装

Posted 大雾哥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql5.7.21源码安装相关的知识,希望对你有一定的参考价值。

1.下载安装包

 

2.安装依赖包

MySQL依赖于libaio 库。如果这个库没有在本地安装,数据目录初始化和后续的服务器启动步骤将会失败。请使用适当的软件包管理器进行安装。例如,在基于Yum的系统上:
shell> yum search libaio 
shell> yum install libaio
 

3.创建一个mysql用户和组

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

4.解压到指定目录

shell> tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz -C /usr/local
shell> cd /usr/local
shell> mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
 

5.配置数据库目录

数据目录:/usr/local/mysql/data 
参数文件my.cnf:/usr/local/mysql/etc/my.cnf 
错误日志log-error:/usr/local/mysql/log/mysql_error.log 
二进制日志log-bin:/usr/local/mysql/log/mysql_bin.log 
慢查询日志slow_query_log_file://usr/local/mysql/log/mysql_slow_query.log 
套接字socket文件:/usr/local/mysql/run/mysql.sock 
pid文件:/usr/local/mysql/run/mysql.pid 
 
shell> mkdir -p /usr/local/mysql/{data,log,etc,run}
shell> chown -R mysql:mysql /usr/local/mysql 
shell> chmod 750 /usr/local/mysql/{data,log,etc,run}
 

6.配置my.cnf文件

在/usr/local/mysql/etc/下创建my.cnf文件,加入如下参数,其他参数根据需要配置
[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
 
[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 128M
max_connections = 2048
open_files_limit = 65535
 
skip-name-resolve
lower_case_table_names=1
 
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=\'SET NAMES utf8mb4\'
 
 
innodb_buffer_pool_size = 128M
innodb_log_file_size = 128M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
 
 
key_buffer_size = 16M
 
log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/log/mysql_bin.log
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
 
 
tmp_table_size = 16M
max_heap_table_size = 16M
query_cache_type = 0
query_cache_size = 0
 
server-id=1
 

7.设置临时密码

grep \'temporary password\' /usr/local/mysql/log/mysql_error.log
 

8.初始化

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data --initialize
 
9.将mysqld设置开启自动启动
 
cp /usr/local/mysql/support-files/mysql.server    /etc/init.d/mysqld
chkconfig --add mysqld
 
10.复制配置文件my.cnf
 
cp /usr/local/mysql/etc/my.cnf    /etc/my.cnf  (提示覆盖就覆盖)
 
11.启动mysql服务
 
service mysql start
 
12.进入mysql
cd /usr/local/mysql/bin 
./ mysql -u root -p(临时密码)
 
13.修改密码
重新设置密码
SET PASSWORD FOR\'root\'@localhost=PASSWORD(\'admin\');   #对应的换成你自己的密码即可
14、开启远程权限
 
grant all privileges on *.* to \'新用户名\'@\'%\' identified by \'新密码\';
flush privileges;
 
15.配置环境变量
 
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
 
 
 
 
 
 
 
 
 
 
 
 

以上是关于mysql5.7.21源码安装的主要内容,如果未能解决你的问题,请参考以下文章

CentOS6.9安装mysql5.7.21教程

win10安装MySQL5.7.21

Mysql5.7.21安装文档

Centos7系统编译安装Mysql5.7.21

MySQL5.7.21安装及配置

centos7上安装mysql5.7.21流程