1.下载二进制安装包
mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
tar -xvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
2.拷贝安装包和配置文件(如果没有特殊情况,将安装包解压放置在该目录)
cp -rf mysql /usr/local/mysql
cp -rf my5.7.cnf /etc/my.cnf
3.创建mysql用户
useradd mysql
4.添加数据目录
mkdir -p /home/mysql3306/mysql3306
mkdir -p /home/mysql3306/logs
5.修改目录权限
chown mysql:mysql -R /home/mysql3306
6.修改配置文件
socket = /tmp/mysql.sock(socket文件存放位置)
datadir = /home/mysql3306/mysql3306(数据文件存放目录)
server-id = 12023306(设置serverid 命名规则:ip后两位+端口号)
port = 3306(启动端口)
innodb_buffer_pool_size = 1024M(innodb buffer pool大小)
*如果是核心节点单实例 配置成系统总内存的75%左右,如果不是核心节点则按照具体业务压力来设置
7.初始化数据库(确认2个OK)
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --basedir=/usr/local/mysql --datadir=/home/mysql3306/mysql3306 --user=mysql
--initialize 初始化后自动设置随机密码
--initialize-insecure 初始化不进行随机密码的赋予
--basedir=/usr/local/mysql mysql安装目录
--datadir=/home/mysql3306/mysql3306 mysql数据目录
在mysql-error.log中寻找初始密码
2018-03-13T07:18:45.762441+08:00 1 [Note] A temporary password is generated for root@localhost: W2O?kK-g#:y7
8.启动mysql5.7
-
# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
-
[2] 2478
-
[root@mysql5 logs]# 2018-03-12T23:23:23.847910Z mysqld_safe Logging to '/home/mysql3306/logs/mysql-error.log'.
-
2018-03-12T23:23:23.886684Z mysqld_safe Starting mysqld daemon with databases from /home/mysql3306/mysql3306
9.
进入mysql5.7
# /usr/local/mysql/bin/mysql -S /tmp/mysql3306.sock -p
初始化密码
-
mysql> show databases;
-
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
-
mysql> set password=password('root')
-
-> ;
-
Query OK, 0 rows affected, 1 warning (0.00 sec)
-
-
mysql> flush privileges;
-
Query OK, 0 rows affected (0.02 sec)
10.配置环境变量
vi /etc/profile
export MYSQL_HOME=/usr/local/mysql
PATH=$PATH:$MYSQL_HOME/bin
如果系统之前自带低版本mysql,则会发生下面的情况,没有指向预定的路径:
[root@mysql5 logs]# which mysql
/usr/bin/mysql
删除之前版本的mysql
yum -y remove mysql*
source /etc/profile
或者
rm -rf /usr/bin/mysql*
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql