1.从官网下载mysql 离线版版安装包 mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz;
2.上传安装包mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz 到 centos 7 的 /usr/tool/ 目录 ;
3.进入/usr/tool/ —> cd /usr/tool;
4.解压安装包:tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz;
5.安装依赖: yum -y install perl perl-devel autoconf libaio;
6.进入/usr/local/mysql/ —>cd /usr/local/mysql/;
7.创建data目录:mkdir /usr/local/mysql/data;
8.添加mysql用户组和用户:
groupadd mysql;
useradd -r -g mysql -s /bin/false mysql;
9. 修改目录拥有者为mysql:chown -R mysql:mysql ./
10.初始化数据(下面是一条语句):
./bin/mysqld --initialize --user=mysql
–basedir=/usr/local/mysql
–datadir=/usr/local/mysql/data
–pid-file=/usr/local/mysql/data/mysql.pid
–tmpdir=/tmp
11.复制生成的密码(登录mysql时用):
12.复制配置文件到/etc/my.cnf:cp -a ./support-files/my-default.cnf /etc/my.cnf (选择y)
13.mysql的服务脚本放到系统服务中:
cp -a ./support-files/mysql.server /etc/init.d/mysqld
14.赋予可执行权限:chmod +x /etc/init.d/mysqld
15.添加服务:chkconfig --add mysqld (可用chkconfig --list命令查看,3,4,5都是ON证明已启动)
16.修改my.cnf文件:vi /etc/my.cnf, 编辑添加如下内容:
log-bin = /home/data/logs/mysql/binlog/mysql-bin #开启二进制日志功能,binlog数据位置
log-bin-index = /home/data/logs/mysql/binlog/mysql-bin.index
log_bin_trust_function_creators = 1
binlog_cache_size = 1M
binlog_format = ROW
expire_logs_days = 30 #超过30天的binlog删除
max_connections = 500 #最大连接数
port = 3306
socket = /tmp/mysql.sock
pid-file = /usr/local/mysql/mysql.pid
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log_error =/home/data/logs/mysql/mysql-error.log
user = mysql
character-set-server = utf8
back_log = 1024
server-id = 1
long_query_time = 1 #开启慢查询
slow_query_log = 2 #慢查询时间(s)
slow_query_log_file = /home/data/logs/mysql/mysql-slow.log
>>>>>>
以下是在线安装5.7版本的
[root@CentOS ~]# yum install -y mysql-server
[root@CentOS ~]# service mysqld start
[root@CentOS ~]# mysqladmin -u root password 'root'
[root@CentOS ~]# mysql -u root -proot
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> delete from user where password='';
Query OK, 4 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
2、进入/etc/mysql/mysql.conf.d 目录下的 mysqld.cnf 文件中需要把下面以上注释掉,使所以主机都可以链接
bind-address = 127.0.0.1