操作系统:3.10.0-514.el7.x86_64
安装包:mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
1:检查是否安装了 libaio(centos7默认安装)
rpm -qa | grep libaio
2:解压
# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
# cd /usr/local/
# mkdir mysql
# mv /app/mysql-5.7.25-linux-glibc2.12-x86_64/* mysql/
3:创建mysql用户
# groupadd mysql
# useradd -r -g mysql mysql
4:创建相关目录以及授权
# cd mysql/
# chown -R mysql:mysql ./
# mkdir data
# mkdir -p /var/lib/mysql
# chmod 766 /var/lib/mysql/ -R
# chown mysql:mysql /var/lib/mysql/ -R
5:修改配置文件
#vi /etc/my.cnf
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
#skip-name-resolve
#设置3306端口
port=3306
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#lower_case_table_name=1
max_allowed_packet=16M
6:启动
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2019-04-15T14:20:38.757727Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-15T14:20:40.143729Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-15T14:20:40.429582Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-15T14:20:40.571055Z 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: a5a4ce13-5f89-11e9-8595-d850e6b87b68.
2019-04-15T14:20:40.585591Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-15T14:20:40.586435Z 1 [Note] A temporary password is generated for root@localhost: OR>sa;aya8aj
7:设置开机启动
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
8:启动
# service mysqld start
Starting MySQL. SUCCESS!
9:配置环境变量
vi /etc/profile
#MYSQL
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
10:修改root用户密码
(1)修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1
这一行配置让 mysqld 启动时不对密码进行验证
(2)重启 mysqld 服务:systemctl restart mysqld
(3)使用 root 用户登录到 mysql:mysql -u root
(4)切换到mysql数据库,更新 user 表:
mysql> use mysql;
mysql> update user set authentication_string = password('mysql'), password_expired = 'N', password_last_changed = now() where user = 'root';
mysql> flush privileges;
在之前的版本中,密码字段的字段名是 password,5.7版本改为了 authentication_string
(5)退出 mysql,编辑 /etc/my.cnf 文件,删除 skip-grant-tables=1 的内容
(6)重启 mysqld 服务,再用新密码登录即可
# service mysqld restart
# mysql -uroot -pmysql
11:增加防火墙策略
# firewall-cmd --zone=public --add-port=3306/tcp --permanent
# firewall-cmd --reload