导航

Linux CentOS7.5上二进制安装MySQL5.7.23

Posted on 2018-10-16 14:35  许爱琪  阅读(561)  评论(1编辑  收藏  举报

1.下载二进制文件

cd /usr/local/src/
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

2.创建MySQL组和用户

groupadd mysql
useradd -g mysql mysql
passwd mysql

3.创建安装目录、数据目录、配置目录等

mkdir -p /usr/local/mysql/
mkdir -p /usr/local/mysql/data
mkdir -p /usr/local/mysql/etc
mkdir -p /usr/local/mysql/log

chown -R mysql:mysql /usr/local/mysql/

4.安装依赖包

yum install libaio numactl

5.安装mysql

su - mysql
cd /usr/local/src/
tar -xzvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
mv /usr/local/src/mysql-5.7.23-linux-glibc2.12-x86_64/* /usr/local/mysql/

6.创建my.cnf配置文件

cat > /usr/local/mysql/etc/my.cnf << EOF
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
log-error=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
lower_case_table_names = 1 #不区分大小写
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
EOF

7.初始化mysql

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
grep 'temporary password' mysqld.log #记录默认密码

8.设置开机启动

su - root
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld chkconfig --list systemctl start mysqld

9.登录数据库并修改密码

[mysql@mysql log]$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> SET PASSWORD = PASSWORD('abc123');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> UPDATE `mysql`.`user` SET `Host` = '%', `User` = 'root' WHERE (`Host` = 'localhost') AND (`User` = 'root'); Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye

 

1.下载二进制文件