本次分享如何在Linux下安装MySQL 5.7
操作系统版本:RedHat/CentOS 6.6 X64
MySQL版本:5.7.11
安装方式:二进制
安装过程:
[
root@gusha2
~]# mkdir /data/dbwyzc -p
1、创建MySQL安装目录
2、创建一个不允许登录的MySQL用户及组
Creating mailbox file: File exists
uid=500(mysql) gid=500(mysql) groups=500(mysql)
3、解压下载下来的MySQL安装包
mysql-5.7.11-linux-glibc2.5-x86_64 mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
做个软连接到/usr/local/mysql
lrwxrwxrwx. 1 root root 46 Mar 24 02:43 mysql -> /data/mysql/mysql-5.7.11-linux-glibc2.5-x86_64
4、创建datadir及日志存储路径
5、授权
6、因为是选择从MySQL压缩包中初始化MySQL,不是直接安装MySQL,需手动解决找不到mysql命令的问题
source /etc/profile
7、关闭防火墙及selinux
SELINUX=disabled
8、修改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,则会创建空密码的
root@localhost
账号,否则会创建带密码的
root@localhost
账号,密码直接写在 log-error 日志文件中
[
root@gusha2
bin]#
mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize --initialize-insecure
auto.cnf ibdata1 ib_logfile1 performance_schema
ib_buffer_pool ib_logfile0 mysql sys
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]
root@localhost
is created with an empty password ! Please consider switching off the --initialize-insecure option.
10、添加使用service快速启动MySQL
magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
Starting MySQL. [ OK ]
之后给root用户设置个密码:
mysql> set password=password('mysql123');
不要被上面繁琐的操作步骤所迷惑,这种方法是我们搭建测试环境及MySQL多实例环境用到的最多的一种安装方法,其操作对于熟练掌握Linux简单命令的人来说已经非常简单了,最重要的是,使用二进制的安装方法,可以让我们在安装MySQL的过程中了解到MySQL各文件的位置、作用、MySQL初始化的时候都做了哪些工作等。
更多精彩MySQL内容 请关注我哦!