安装包下载 https://dev.mysql.com/downloads/mysql/ 根据系统版本下载
安装新版mysql前,需将系统自带的mariadb-lib卸载 1 2 3 4 [root@hadoop ~] mariadb-libs-5.5.52-1.el7.x86_64 [root@hadoop ~] [root@hadoop ~]
解压安装包 1 tar -xvf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
安装 1 rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
1 rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
1 2 rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
在安装之前需要安装libaio
1 2 [root@hadoop app] libaio-0.3.109-13.el7.x86_64
如果不存需要下载离线包:http://mirror.centos.org/centos/6/os/x86_64/Packages/
安装libaio库 1 rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm(若在有网情况下可执行yum install libaio)
安装server 1 rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
出现如下错误:(最好安装服务版的centos,最小化安装会出现如下错误,处理比较麻烦,需要安装各种依赖包)
1 2 3 4 error: Failed dependencies: /usr/bin/perl is needed by mysql-community-server-5.7.20-1.el7.x86_64 perl(Getopt::Long) is needed by mysql-community-server-5.7.20-1.el7.x86_64 perl(strict) is needed by mysql-community-server-5.7.20-1.el7.x86_64
安装依赖包
初始化数据库 1 2 3 4 5 // 指定datadir, 执行后会生成~/.mysql_secret密码文件(5.7以后不在使用) [root@slave mytmp] // 初始化,执行生会在/var/log /mysqld.log生成随机密码 [root@slave mytmp]
更改mysql数据库目录的所属用户及其所属组(没用创建mysql用户) 1 chown mysql:mysql /var/lib/mysql -R
启动mysql systemctl start mysqld.service
问题 Process: 5924 ExecStart=/usr/sbin/mysqld –daemonize –pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)
跟踪日志/var/log/mysqld.log
授权 chmod -R 777 mysql
在启动查看:
登录到mysql,更改root用户的密码 命令可以查看初始密码
grep 'temporary password' /var/log/mysqld.log
set password=password('123456a?');
创建用户,及作权限分配 1 2 3 4 5 CREATE USER 'sunld' @'%' IDENTIFIED BY '123456a?' ;GRANT ALL PRIVILEGES ON * .* TO 'sunld' @'%' ;flush privileges;
远程登陆授权 1 2 3 grant all privileges on * .* to 'root' @'%' identified by '123456a?' with grant option;flush privileges;
设置mysql开机启动 1 2 3 4 // 检查是否已经是开机启动 systemctl list-unit-files | grep mysqld // 开机启动 systemctl enable mysqld.service
默认配置文件路径
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
配置默认编码为utf8 修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
1 2 3 [mysqld] character_set_server= utf8 init_connect= 'SET NAMES utf8'
参考