oracle官网下载mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz,需要登录,没有账号先注册。
安装目录尽量放在/usr/local/mysql下,因为MySQL启动脚本默认的也是这个目录。
将安装包移动到/usr/local
解压:
tar xvf mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz
将解压后的文件夹重命名为mysql:
mv mysql-5.7.15-linux-glibc2.5-x86_64 mysql
[root@iZ25xf935m3Z mysql]# pwd
/usr/local/mysql
[root@iZ25xf935m3Z mysql]# ls
bin COPYING docs include lib man README share support-files
//创建数据仓库,将数据存放在/data/mysql目录中:
[root@iZ25xf935m3Z mysql]# mkdir /data
[root@iZ25xf935m3Z mysql]# mkdir /data/mysql
增加用户组mysql:
[root@iZ25xf935m3Z mysql]# groupadd mysql
为MySQL创建单独用户mysql,设置不能登录Linux系统,并把/usr/local/mysql分配给mysql组的mysql:
[root@iZ25xf935m3Z mysql]# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
授权:
[root@iZ25xf935m3Z mysql]# chown -R mysql .
[root@iZ25xf935m3Z mysql]# chgrp -R mysql .
数据仓库同样授权:
chown -R mysql /data/mysql
初始化并获得初始root密码:
[root@iZ25xf935m3Z usr]# cd mysql
[root@iZ25xf935m3Z mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/mysql --datadir=/data/mysql
2016-09-13T09:29:58.455618Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-09-13T09:30:00.539528Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-09-13T09:30:00.796729Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-09-13T09:30:00.876881Z 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: a4d2a8d4-7994-11e6-a1a1-00163e0a06f0.
2016-09-13T09:30:00.879300Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-09-13T09:30:00.880010Z 1 [Note] A temporary password is generated for root@localhost: Z68kTLj(6l6_
安全设置:
[root@iZ25xf935m3Z mysql]# bin/mysql_ssl_rsa_setup --datadir=/data/mysql
Generating a 2048 bit RSA private key
....................................................................+++
.....................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
.......................................................................................................................+++
.......................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
...............................+++
.................+++
writing new private key to 'client-key.pem'
-----
修改系统配置文件
[root@iZ25xf935m3Z mysql]# cd support-files/
[root@iZ25xf935m3Z support-files]# ls
magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@iZ25xf935m3Z support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@iZ25xf935m3Z support-files]# cp mysql.server /etc/init.d/mysql
vim /etc/init.d/mysql
vim /etc/my.cnf
后台启动MySQL:
[root@iZ25xf935m3Z mysql]# bin/mysqld_safe --user=mysql &
客户端连接:
bin/mysql --user=root –p
--输入上面生成的临时密码
修改root密码:
mysql> set password=password('A123456');
授权给root:
mysql>grant all privileges on *.* to root@'%' identified by 'A123456';
mysql> flush privileges;
添加系统路径
# vim /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
配置mysql自动启动
# chmod 755 /etc/init.d/mysql
# chkconfig --add mysql
# chkconfig --level 345 mysql on