MySQL 5.7 安装(二进制包)

增加用户:

#添加普通用户mysql,设置不允许登录系统,不创建家目录:
useradd -s /sbin/nologin mysql

创建mysql初始化目录:

mkdir -p /data/mysql

安装mysql 5.7:

#mysql 官方下载新版的mysql 到 /tmp 目录下:
wget -O /tmp/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
#解压:
tar zxf /tmp/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.7.12-linux-glibc2.5-x86_64 /usr/local/mysql
#复制mysql 的启动脚本到/etc/init.d 目录下并重命名为mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
#依据具体数据目录进行修改
sed -i 's/^datadir=/datadir=\/data\/mysql/' /etc/init.d/mysqld
sed -i 's/^basedir=/basedir=\/usr\/local\/mysql/' /etc/init.d/mysqld

配置 my.cnf:

[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 1
socket = /tmp/mysql.sock
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

修改mysql数据目录属主为mysql:

chown -R mysql:mysql /data/mysql

初始化mysql:

注意最后的密码

/usr/local/mysql/bin/mysqld --initialize
2015-12-23T13:39:46.978926Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-23T13:39:46.978966Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2015-12-23T13:39:46.978970Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2015-12-23T13:39:47.138443Z 0 [Warning] InnoDB: New log files created, LSN=45790
2015-12-23T13:39:47.192355Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-12-23T13:39:47.276047Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a1f1f232-a97a-11e5-b180-00155d016a04.
2015-12-23T13:39:47.283047Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2015-12-23T13:39:47.283673Z 1 [Note] A temporary password is generated for root@localhost: Iq:V)7O*za0*

说明:如果在 mysql 的启动脚本文件和mysql 的主配置文件中不声明datadir= ,那么,执行mysqld –initialize 时默认会将数据库初始化到 /usr/local/mysql/data 目录下,且在启动mysqld服务之前,需要将 /usr/local/mysql 的所属主和组都修改为mysql.

配置mysql 系统环境变量:

echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
#刷新系统环境变量,使上面的配置立即生效
source /etc/profile

启动mysql:

chown -R mysql:mysql /usr/local/mysql/
service mysqld start

检查启动状态:

ps aux | grep mysql
netstat -antlp | grep 3306

修改root默认密码:

mysql -uroot -p 
mysql> SET password = PASSWORD("password");
mysql> FLUSH privileges;
  • linux/mysql/mysql_5.7_安装_二进制包.txt
  • 最后更改: 2020/08/05 03:45
  • (外部编辑)