【CentOS 7】安装【MySQL 5.7.19】二进制
xixuefeng
Linux, MySQL, MySQL-Install
2017-08-10 17:32:41
2,326 次浏览
【CentOS 7】安装【MySQL 5.7.19】二进制已关闭评论
操作系统:CentOS-7-x86_64-DVD-1611.iso
数据库:mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
安装介质的下载及操作系统安装就不描述了,直接在Linux上安装MySQL
1:创建用户和组
1 2 3 |
[root@mss ~]# groupadd mysql [root@mss ~]# useradd -r -g mysql mysql [root@mss ~]# |
2:创建目录
1 2 3 4 5 6 7 |
## 用于存放MySQL安装介质 [root@mss ~]# mkdir /soft [root@mss ~]# ## 创建mysql数据存储路径,并修改属主、属组 [root@mss ~]# mkdir -p /data/db/mysql/2587 [root@mss ~]# chown -R mysql.mysql /data [root@mss ~]# |
3:上传安装介质到/soft下,步骤略
4:解压缩
1 2 3 4 5 6 7 |
## MySQL安装介质解压缩至/usr/local目录下 [root@mss ~]# cd /soft/ [root@mss soft]# tar -xvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local ## 将解压缩后的目录改名为 mysql [root@mss soft]# cd /usr/local [root@mss local]# mv mysql-5.7.19-linux-glibc2.12-x86_64/ mysql [root@mss local]# |
5:编译安装并初始化mysql
1 2 3 4 5 6 7 8 9 |
[root@mss ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/db/mysql/2587 --basedir=/usr/local/mysql 2017-08-10T10:52:56.525511Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-08-10T10:52:58.855527Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-08-10T10:52:59.090373Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-08-10T10:52:59.680188Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 132700f5-7dba-11e7-b2bf-000c2969339d. 2017-08-10T10:52:59.724773Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-08-10T10:52:59.725486Z 1 [Note] A temporary password is generated for root@localhost: tfY9Vw;jXmxn [root@mss ~]# ## 记住最后一行的 root 口令 root@localhost: tfY9Vw;jXmxn |
6:编辑/etc/my.cnf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[client] socket=/data/db/mysql/2587/mysql.sock [mysqld] datadir=/data/db/mysql/2587 socket=/data/db/mysql/2587/mysql.sock ## 在这里我们未使用默认端口,使用的是2587端口 port = 2587 basedir=/usr/local/mysql user = mysql symbolic-links=0 [mysqld_safe] log-error=/data/db/mysql/2587/mariadb.log pid-file=/data/db/mysql/2587/mariadb.pid |
7:启动mysql服务
1 2 3 4 |
[root@mss etc]# /usr/local/mysql/support-files/mysql.server start Starting MySQL.Logging to '/data/db/mysql/2587/mariadb.log'. SUCCESS! [root@mss etc]# |
8:以服务的方式启动mysql
1 2 3 4 5 6 7 8 |
## 通过软连接实现可通过service启动、停止mysql [root@mss etc]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql [root@mss etc]# ## 重启 mysql 数据库 [root@mss etc]# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! [root@mss etc]# |
9:将mysql可执行程序连接到/usr/bin 目录下
1 2 3 |
## 这样做就不需要修改环境变量了,已经可以识别mysql这个可执行程序了 [root@mss etc]# ln -s /usr/local/mysql/bin/mysql /usr/bin [root@mss etc]# |
10:以root身份登录mysql(同时也算验证了一下第9步的软链接)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
[root@mss etc]# mysql -u root -p Enter password: <这里输入的密码就是第5步初始化时让大家记住的root口令> Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.19 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. mysql> ## 修改一下root口令 mysql> alter user 'root'@'localhost' identified by 'oracle'; Query OK, 0 rows affected (0.00 sec) 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> update user set user.Host='%' where user.User='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye [root@mss etc]# |
11:CentOS 7 防火墙打开2587端口
1 2 3 4 |
## CentOS 7 默认的是firewall作为防火墙,而非之前经比较熟悉的 iptables ## 当然,最省事儿的方法是直接关闭防火墙 [root@mss ~]# firewall-cmd --zone=public --add-port=2587/tcp --permanent [root@mss ~]# firewall-cmd --reload |
12:其他,CentOS 7 防火墙设置白名单,指定IP和端口
1 2 3 4 5 |
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.31.190" port protocol="tcp" port="2587" accept" firewall-cmd --reload firewall-cmd --list-all ## 删除规则,将--add 改为 --remove |