本次分享如何在Linux下安装MySQL 5.7
操作系统版本:RedHat/CentOS 6.6 X64
MySQL版本:5.7.11
安装方式:二进制
MySQL下载地址:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
安装过程:
[[email protected] ~]# mkdir /data/dbwyzc -p
1、创建MySQL安装目录
2、创建一个不允许登录的MySQL用户及组
[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -g mysql -s /sbin/nologin -d /data/mysql mysql
Creating mailbox file: File exists
[[email protected] ~]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
3、解压下载下来的MySQL安装包
[[email protected] ~]# mv /root/Desktop/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz /data/mysql/
[[email protected] ~]# cd /data/mysql/
[[email protected] mysql]# tar xf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
[[email protected] mysql]# ls
mysql-5.7.11-linux-glibc2.5-x86_64 mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
做个软连接到/usr/local/mysql
[[email protected] mysql]# cd /usr/local/
[[email protected] local]# ln -s /data/mysql/mysql-5.7.11-linux-glibc2.5-x86_64 mysql
[[email protected] local]# ls -l mysql
lrwxrwxrwx. 1 root root 46 Mar 24 02:43 mysql -> /data/mysql/mysql-5.7.11-linux-glibc2.5-x86_64
4、创建datadir及日志存储路径
[[email protected] local]# cd /data/dbwyzc/
[[email protected] dbwyzc]# ls
[[email protected] dbwyzc]# mkdir {data,logs}
5、授权
[[email protected] dbwyzc]# chown -R mysql.mysql /data/dbwyzc/
[[email protected] dbwyzc]# chown -R mysql.mysql /usr/local/mysql/
6、因为是选择从MySQL压缩包中初始化MySQL,不是直接安装MySQL,需手动解决找不到mysql命令的问题
[[email protected] dbwyzc]# echo ‘export PATH=$PATH:/usr/local/mysql/bin‘ >> /etc/profile
[[email protected] dbwyzc]# source !$
source /etc/profile
7、关闭防火墙及selinux
[[email protected] dbwyzc]# chkconfig iptables off
[[email protected] dbwyzc]# vi /etc/sysconfig/selinux
SELINUX=disabled
8、修改my.cnf
[[email protected] dbwyzc]# vi /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/dbwyzc/data
socket=/tmp/mysql.sock
log-error=/data/dbwyzc/logs/mysqld.log
pid-file=/data/dbwyzc/mysqld.pid
9、初始化MySQL
在5.7中,推荐使用mysqld --initialize对数据库进行初始化(mysql_install_db已经不再推荐使用),在初始化时如果加上--initialize-insecure,则会创建空密码的 [email protected] 账号,否则会创建带密码的 [email protected] 账号,密码直接写在 log-error 日志文件中
[[email protected] mysql]# cd bin/
[[email protected] bin]# mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize --initialize-insecure
[[email protected] bin]# ls /data/dbwyzc/data/
auto.cnf ibdata1 ib_logfile1 performance_schema
ib_buffer_pool ib_logfile0 mysql sys
[[email protected] bin]# ls /data/dbwyzc/logs/
mysqld.log
[[email protected] bin]# cat /data/dbwyzc/logs/mysqld.log
2016-03-23T20:45:41.774933Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-03-23T20:45:43.665168Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-03-23T20:45:43.939168Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-03-23T20:45:44.025867Z 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: 368bbcd5-f138-11e5-aad0-000c29f650ca.
2016-03-23T20:45:44.029664Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2016-03-23T20:45:44.031662Z 1 [Warning] [email protected] is created with an empty password ! Please consider switching off the --initialize-insecure option.
10、添加使用service快速启动MySQL
[[email protected] bin]# cd ../
[[email protected] mysql]# ls support-files/
magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysql
[[email protected] mysql]# service mysql start
Starting MySQL. [ OK ]
之后给root用户设置个密码:
[[email protected] mysql]# mysql
mysql> set password=password(‘mysql123‘);
不要被上面繁琐的操作步骤所迷惑,这种方法是我们搭建测试环境及MySQL多实例环境用到的最多的一种安装方法,其操作对于熟练掌握Linux简单命令的人来说已经非常简单了,最重要的是,使用二进制的安装方法,可以让我们在安装MySQL的过程中了解到MySQL各文件的位置、作用、MySQL初始化的时候都做了哪些工作等。
更多精彩MySQL内容 请关注我哦!