代码改变世界

Linux 安装MySQL5.7.18

2017-06-18 07:25  DataBases  阅读(832)  评论(0编辑  收藏  举报

https://dev.mysql.com/downloads/mysql/
Linux-Generic

md5sum mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

Linux环境检查

1 关闭numa

[root@node130 ~]#  vim /boot/grub/grub.conf
title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=cb7d8bdc-28a5-4dbd-b04a-3ad9ee3e6bba rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet numa=off

[root@node130 ~]# numactl --hardware

[root@node130 ~]#numactl --show

2限制设置 /etc/security/limits.conf
[root@node130 ~]# vim /etc/security/limits.conf
* soft    nofile  1024000
* hard    nofile  1024000
* soft    nproc   unlimited
* hard    nproc   unlimited
* soft    core    unlimited
* hard    core    unlimited
* soft    memlock unlimited
* hard    memlock unlimited

3 Swap
[root@node130 ~]# vim /etc/sysctl.conf
vm.swappiness=0

sysctl -p 生效
[root@node130 ~]# sysctl -a|grep swap
vm.swappiness = 0

6 selinux & iptables

selinux:
[root@node130 ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
SELINUXTYPE=targeted

[root@node130 ~]# getenforce
Disabled

setenforce 0
getenforce

chkconfig --list|grep iptables
chkconfig --del iptables

[root@node130 ~]# chkconfig --list|grep iptables
iptables        0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@node130 ~]# chkconfig --del iptables
[root@node130 ~]# chkconfig --list|grep iptables

[root@node130 ~]# reboot

1创建账户
[root@node130 home]# groupadd mysql
[root@node130 home]# useradd -g mysql -d /user/local/mysql -s /sbin/nologin -M mysql
[root@node130 home]# id mysql
uid=505(mysql) gid=506(mysql) groups=506(mysql)

[root@node130 home]# mkdir /opt/mysql
[root@node130 mysql]# tar xvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

[root@node130 ~]# cd /usr/local/
cd /user/local/
[root@node130 local]# ln -s /opt/mysql/mysql-5.7.18-linux-glibc2.5-x86_64 mysql

[root@node130 local]# chown -R mysql:mysql mysql/

[root@node130 mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
[root@node130 mysql]# source /etc/profile

/data 是一个单独挂载的分区

[root@node130 mysql]# mkdir -p /data/mysql/mysql_3306/{data,logs,tmp}

[root@node130 mysql_3306]# chown -R mysql:mysql /data/mysql/mysql_3306/

[root@node130 ~]# cp /opt/my.cnf /etc/

初始化

[root@node130 mysql]# ./bin/mysqld  --defaults-file=/etc/mysql3306.cnf --initialize
[root@node130 mysql]# cat /data/mysql/mysql_3306/data/error.log |grep password
2017-04-28T06:36:55.453219Z 1 [Note] A temporary password is generated for root@localhost: rFcPw<f;k4+1

启动

[root@node130 mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@node130 mysql]# /etc/init.d/mysql start
Starting MySQL...................... SUCCESS!
cp support-files/mysql.server /etc/init.d/mysql

or

[root@node130 ~]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf &
[1] 2787

[root@node130 tmp]# mysql -S /tmp/mysql.sock -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-log

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

"(unknown)@localhost:mysql.sock  [(none)]>alter user user() identified by '123456';
Query OK, 0 rows affected (0.01 sec)

"root@localhost:mysql.sock  [(none)]>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.09 sec)

"root@localhost:mysql.sock  [(none)]>exit
Bye
[root@node130 etc]# mysqladmin -S /tmp/mysql.sock -p shutdown
Enter password: