环境:centos 7,mysql版本:5.7.14
解压mysql5.7压缩包
将解压的文件夹重命名为mysql5.7
命令省略
创建用户
groupadd mysql
useradd -r -g mysql mysql
授权文件夹
chmod 750 mysql5.7
chown -R mysql mysql5.7
chgrp -R mysql mysql5.7
在mysql5.7中创建存放数据的文件夹
mkdir data
chmod 755 data
chown 750 data
chown -R mysql data
chgrp -R mysql data
在mysql5.7中创建存放pid和log目录并授权(省略命令)
配置mysql配置文件
在/etc/my.cnf配置文件上配置
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
basedir=/opt/mysql5.7
datadir=/opt/mysql5.7/data
port=3306
socket=/opt/mysql5.7/mysql.sock
pid-file=/opt/mysql5.7/pid/mysql.pid
log-error=/opt/mysql5.7/log/error.log
character_set_server=utf8
explicit_defaults_for_timestamp=true
[client]
default-character-set=utf8
进入bin目录初始化
./bin/mysqld --user=mysql --basedir=/opt/mysql5.7 --datadir=/opt/mysql5.7/data --initialize
初始化后进入指定的日志目录查看生成的日志
里面有初始化密码
修改在support-files下服务脚本mysql.service配置basedir和datadir
basedir=/opt/mysql5.7
datadir=/opt/mysql5.7/data
启动运行
./mysql.server start --user=mysql
查看服务是否启动
ps -ef | grep mysql
通过bin目录下的mysql客户端连接mysql
./bin/mysql -uroot -p
出现
原因:由于将生成的mysql.sock文件放到mysql5.7目录中,因此找不到
通过创建软链接来处理
ln -s /opt/mysql5.7/mysql.sock /tmp/mysql.sock
在次连接,使用在初始化时,在error.log文件中生成的临时密码进入
-----------------------------------------------------------------------------------------------------------------------------------------------------------
测试使用
show databases;
出现
更新密码
alter user 'root'@'localhost' identified by 'root';
将root用户设置成可以远程登录连接
grant all privileges on *.* to root@'%' identified by 'root';
flush privileges;
使用客户端使用root/root登录