linux 下安装 mysql5.7
:1. 安装包准备
mysql 下载地址:
https://dev.mysql.com/downloads/mysql/
- 检查环境是否有mysql
命令:
rpm -qa | grep mysql
cat /etc/group | grep mysql
如果有则删除
命令:
find / -name mysql|xargs rm -rf
- 先安装必备库
命令:
yum search libaio
yum install libaio
结果
[root@localhost ~]# yum search libaio
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.btte.net
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.btte.net
(1/2): base/7/x86_64/primary_db | 5.6 MB 00:00:01
(2/2): updates/7/x86_64/primary_db | 7.8 MB 00:00:01
================================ N/S matched: libaio ================================
libaio.i686 : Linux-native asynchronous I/O access library
libaio.x86_64 : Linux-native asynchronous I/O access library
libaio-devel.i686 : Development files for Linux-native asynchronous I/O access
libaio-devel.x86_64 : Development files for Linux-native asynchronous I/O access
名称和简介匹配 only,使用“search all”试试。
[root@localhost ~]# yum install libaio
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.btte.net
软件包 libaio-0.3.109-13.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@localhost ~]#
- 检查mysql组和用户是否存在,如无创建
命令:
groupadd mysql
useradd -g mysql mysql
passwd mysql
连续输入两次密码完成用户创建
上传软件包
- 解压TAR包,更改所属的组和用户
命令:
cd /home/mysql/
tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
cd /usr/local/mysql/
结果:
[root@localhost mysql]# mv mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/mysql
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql
[root@localhost mysql]# ls
mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin COPYING docs include lib man README share support-files
[root@localhost mysql]# ll
总用量 36
drwxr-xr-x. 2 mysql mysql 4096 8月 27 12:18 bin
-rw-r--r--. 1 mysql mysql 17987 6月 22 22:13 COPYING
drwxr-xr-x. 2 mysql mysql 55 8月 27 12:18 docs
drwxr-xr-x. 3 mysql mysql 4096 8月 27 12:18 include
drwxr-xr-x. 5 mysql mysql 229 8月 27 12:18 lib
drwxr-xr-x. 4 mysql mysql 30 8月 27 12:18 man
-rw-r--r--. 1 mysql mysql 2478 6月 22 22:13 README
drwxr-xr-x. 28 mysql mysql 4096 8月 27 12:18 share
drwxr-xr-x. 2 mysql mysql 90 8月 27 12:18 support-files
- 创建目录并授权
命令
mkdir data mysql-files
chmod 750 mysql-files
chown -R mysql .
chgrp -R mysql .
结果:
[root@localhost mysql]# mkdir data mysql-files
[root@localhost mysql]# chmod 750 mysql-files
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# ll
总用量 36
drwxr-xr-x. 2 mysql mysql 4096 8月 27 12:18 bin
-rw-r--r--. 1 mysql mysql 17987 6月 22 22:13 COPYING
drwxr-xr-x. 2 mysql mysql 6 8月 27 12:21 data
drwxr-xr-x. 2 mysql mysql 55 8月 27 12:18 docs
drwxr-xr-x. 3 mysql mysql 4096 8月 27 12:18 include
drwxr-xr-x. 5 mysql mysql 229 8月 27 12:18 lib
drwxr-xr-x. 4 mysql mysql 30 8月 27 12:18 man
drwxr-x---. 2 mysql mysql 6 8月 27 12:21 mysql-files
-rw-r--r--. 1 mysql mysql 2478 6月 22 22:13 README
drwxr-xr-x. 28 mysql mysql 4096 8月 27 12:18 share
drwxr-xr-x. 2 mysql mysql 90 8月 27 12:18 support-files
- 初始化数据库
命令
bin/mysqld --initialize --user=mysql
结果:
[root@localhost mysql]# bin/mysqld --initialize --user=mysql
2017-08-27T04:25:05.984358Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-27T04:25:06.293545Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-08-27T04:25:06.381713Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-08-27T04:25:06.459091Z 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: b4410940-8adf-11e7-b689-080027b199be.
2017-08-27T04:25:06.467223Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-08-27T04:25:06.469594Z 1 [Note] A temporary password is generated for root@localhost: koYyPqyL2y#t
初始化数据库并生成临时密码 :koYyPqyL2y#t 需要记录下来
[注意]root@localhost生成临时密码,也就是root@localhost:后的字符串
- 生成RSA私钥,可以跳过此步骤 个人建议不用执行
mysql_ssl_rsa_setup
需要openssl
支持,用于启用数据量ssl连接,需要进一步配置。
参考-MySQL 使用 SSL 连接
命令
bin/mysql_ssl_rsa_setup
结果
[root@localhost mysql]# bin/mysql_ssl_rsa_setup
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
.................................................+++
..............++