Mysql 5.7.20安装配置方法图文教程(Linux)
1. 系统约定
安装文件下载目录: /data/software
Mysql目录安装位置: /usr/local/mysql
数据库保存位置: /opt/mysql/data
日志保存位置: /data/log/mysql
2. 下载mysql
在官网: https://dev.mysql.com/downloads/mysql/ 中,选择以下版本的mysql下载:
执行如下命令(直接下载到服务器上):
#mkdir /data/software
#cd /data/software
#wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar
3. 检查数据库文件是否存在,如果存在则删除.
[root@localhost ~]# rpm -qa | grep mysql mysql-5.7.20-linux-glibc2.12-x86_64
[root@localhost ~]# rpm -e mysql-5.7.20-linux-glibc2.12-x86_64 --nodeps
4. 检查mysql组和用户是否存在,如不存在则创建.
[root@localhost ~]# cat /etc/group | grep mysql
[root@localhost ~]# cat /etc/passwd | grep mysql
(下图是mysql组和用户存在:)
// useradd -r 参数表示mysql用户是系统用户,不可用于登录系统.
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql
5. 解压压缩(TAR)包到目标位置
# mkdir /usr/local/mysql ---- 创建文件夹
# cd /data/software
# pwd -----用pwd命令查看默认工作目录的完整路径
# ls/ll
# cd /usr/local
#pwd
# tar -xf /data/software/mysql-5.7.20-linux-glibc2.12-x86_64.tar
# ls/ll
# mv mysql-5.7.14-linux-glibc2.5-x86_64 mysql --- 修改文件名
# ls/ll
6. 安装和初始化数据库配置OS
sudo vim /etc/security/limits.conf ---- sudo是非root用户临时获取root权利来执行
mysql hard nofile 65535
mysql soft nofile 65535
7. 创建数据仓库目录
# mkdir /opt/mysql/data
# ls/ll
8. 安装与初始化DB(配置参数)
[root@localhost mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/opt/mysql/data/
出现错误信息:
2015-11-19 06:49:00 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld
--initialize 2015-11-19 06:49:07 [ERROR] The bootstrap log isn't empty: 2015-11-19T14:49:01.888730Z 0
[ERROR] Can't read from messagefile '/usr/share/mysql/english/errmsg.sys'
造成问题的原因是: mysql_install_db命令已弃用,使用mysqld .所以命令修改为如下:
[root@localhost mysql]# bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/opt/mysql/data/
此处需要注意记录生成的临时密码,如上文:YLi>7ecpe;YP
9. [root@localhost mysql]# bin/mysql_ssl_rsa_setup --datadir=/opt/mysql/data
10. 修改系统配置文件
[root@localhost /]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# ll
[root@localhost support-files]#cp my-default.cnf /etc/my.cnf
[root@localhost support-files]#cp mysql.server /etc/init.d/mysql
[root@localhost support-files]# vim /etc/init.d/mysql
修改以下内容:
[mysqld]
basedir=/usr/local/mysql
datadir=/opt/mysql/data
[root@localhost support-files]# vim /etc/my.cnf
修改以下内容:
[mysqld]
datadir=/opt/mysql/data/
11. 启动mysql
[root@localhost /]# cd /usr/local/mysql
[root@localhost mysql]#bin/mysqld_safe --user=mysql &
[root@localhost mysql]#/etc/init.d/mysqld restart
Shutting down MySQL..2016-08-19T17:25:18.416810Z mysqld_safe mysqld from pid file /usr/local/mysql/data/slave.pid ended
[ OK ]
Starting MySQL
[root@localhost mysql]# bin/mysqld_safe --user=mysql -p
输入上边生成的临时密码
重置密码
mysql> set password=password('********');
给指定的数据库设置登录名和密码
mysql> grant all on gamesp.* to newuser@localhost identified by 'password';
mysql> flush privileges;
如果mysql服务启动成功后,通过navicat等客户端连接不成功时,说明安装mysql的服务器ip不是mysql默认的那几个.解决方案:
mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;
12. 添加系统路径
[root@localhost /]# cd etc
[root@localhost etc]# vi profile
添加的内容如下:
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost /]# source /etc/profile
2. 配置mysql自动启动
[root@localhost /]# chmod 755 /etc/init.d/mysql
[root@localhost /]# chkconfig --add mysql
[root@localhost /]# chkconfig --level 345 mysql on