1.下载MySQL
在官网:http://dev.mysql.com/downloads/mysql/ 中,选择以下版本的mysql下载
2.规划安装目录
安装包存放目录:/data/soft
mysql安装目录:/data/mysql
mysql数据data存放目录:/data/mysql/data
mysql日志log存放目录:/data/mysql/log
3.开始安装mysql
进入安装包存放目录
cd /data/soft
下载安装包
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
解压安装包
tar -zxvf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
进入解压目录,并把内容移动到/data/mysql目录中
cd /data/soft/mysql-5.7.13-linux-glibc2.5-x86_64
mv * /data/mysql
5.进入mysql的安装目录中
cd /data/mysql
6.创建mysql用户以及用户组
groupadd mysql
useradd -g mysql mysql
7.更改目录的所有者
chown –R mysql .
chgrp –R mysql .
8.配置初始化参数
bin/mysqld --initialize --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
注意此处要记录最后面生成的临时密码(结尾:后面的部分)
bin/mysql_ssl_rsa_setup --datadir=/data/mysql/data
9.修改系统配置参数
cd /data/mysql/support-files cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysql
10.修改内容
vi /etc/init.d/mysql
找到basedir和datadir,修改为:
basedir=/data/mysql
datadir=/data/mysql/data
vi /etc/my.cnf
找到basedir和datadir,修改为:
[client]
port= 3306
socket= /data/mysql/mysql.sock
[mysqld]
port= 3306
socket= /data/mysql/mysql.sock
datadir= /data/mysql/data
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
query_cache_limit = 16M
thread_cache_size = 300
innodb_buffer_pool_size = 32M
max_connections = 1000
slow_query_log = on
slow_launch_time = 2
long_query_time = 5
slow_query_log_file = /data/mysql/log/mysql-slow.log
default-storage-engine=INNODB
server-id= 1
log-bin=mysql-bin
innodb_buffer_pool_size = 384M
innodb_log_file_size = 100M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
binlog_format=mixed
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
##4. 启动mysql
cd /data/mysql
bin/mysqld_safe --user=mysql &
登录(密码为上面的临时密码):
bin/mysql -u root –p
set password=password('root');//修改密码成功
##5.添加系统变量
ln -s /data/mysql/bin/* /usr/local/bin/
##6. 添加开机自启
chkconfig --add mysql
##7.远程访问授权
grant all privileges on *.* to root@'%' identified by 'root';
flush privileges;
注意:本文归作者所有,未经作者允许,不得转载