·mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
·目前最新为5.7.16,可以直接下载mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz,
·这里用的是5.7.12,未下载最新的,不过,安装方式一样。
·官网地址: http://www.mysql.com/downloads/
·
·点击Mysql Community Server后进入如下页面:
·
·选择对应位数版本点击Download,目前官网已经更新到5.7.16,可以直接下载最新版本安装,5.7安装方式一样:
·
·进入下载页面点击下载即可:
·
·下载完后通过Xftp等方式上传到linux系统习惯目录下。或者使用centos系统自带的rz进行上传。
·如果系统没有安装过mysql,此步骤不需要
·1. 关闭mysql服务
·
·2. 检查是否有rpm包,如果没有用rpm安装过mysql,不应该有残留,如果有,需要删掉
·检查语法: rpm -qa|grep -i mysql
·删除语法: rpm -e <包的名字>
·如果遇到依赖,无法删除,使用 rpm -e --nodeps <包的名字> 不检查依赖,直接删除rpm包。
·
我安装的是:
查询是否有自带的Mariadb数据库
[root@hdp265dnsnfs ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
#卸载系统自带的Mariadb
[root@hdp265dnsnfs ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
#放到在/usr/local目录下
cd /usr/local
#上传命令选择安装包
rz
#解压缩包
tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
#给包重命名为mysql
mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
#查看mysql目录下有什么东西
[root@bogon mysql]# ll
总用量 626796
drwxr-xr-x. 2 root root 4096 1月 2 01:28 bin
-rw-r--r--. 1 7161 31415 17987 12月 28 2017 COPYING
drwxr-xr-x. 2 root root 55 1月 2 01:28 docs
drwxr-xr-x. 3 root root 4096 1月 2 01:28 include
drwxr-xr-x. 5 root root 229 1月 2 01:28 lib
drwxr-xr-x. 4 root root 30 1月 2 01:28 man
-rw-r--r--. 1 root root 641798603 1月 1 09:22 mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
-rw-r--r--. 1 7161 31415 2478 12月 28 2017 README
drwxr-xr-x. 28 root root 4096 1月 2 01:28 share
drwxr-xr-x. 2 root root 90 1月 2 01:28 support-files
#查询是否有自带的Mariadb数据库
[root@hdp265dnsnfs ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
#卸载系统自带的Mariadb
[root@hdp265dnsnfs ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
#检查mysql是否存在
[root@hdp265dnsnfs ~]# rpm -qa | grep mysql
#检查mysql组和用户是否存在,如无创建
[root@hdp265dnsnfs ~]# cat /etc/group | grep mysql
[root@hdp265dnsnfs ~]# cat /etc/passwd | grep mysql
#创建mysql用户组
[root@bogon selinux]# groupadd mysql
[root@bogon selinux]# useradd -g mysql mysql
#制定password 为111111
[root@bogon selinux]# passwd mysql
更改用户 mysql 的密码 。
新的 密码:
无效的密码: 密码是一个回文
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
#更改所属的组和用户
[root@bogon local]# chown -R mysql mysql
[root@bogon local]# chgrp -R mysql mysql
#创建data目录
[root@bogon mysql]# mkdir data
[root@bogon mysql]# chown -R mysql:mysql data
#这个版本的数据库是没有my.cnf需要创建my.cnf
[root@bogon etc]# touch my.cnf
[root@bogon etc]# vim my.cnf
[root@bogon etc]# cat my.cnf
#查看配置my.cnf
```
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306
# 设置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_names=1
max_allowed_packet=16M
```
#修改config配置
vim /etc/selinux/config
[root@bogon support-files]# vim /etc/selinux/config
```
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#enforcing改为disabled
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
```
·修改目录权限
chown -R mysql:mysql ./
·ln -s /usr/local/mysql/bin/mysql /usr/bin
·如图:
·
·软连接有啥用,说白了,就是给linux系统加上mysql这个命令,linux系统命令放在/usr/bin下,
·与在windows中命令存在C:\Windows\System32目录下一样,windows上命令都是xxx.exe形式,
·比如telnet.exe,如果没有这个文件,windows命令窗口使用的时候就会提示命令telnet命令不存在,
·这个地方操作,就是为了后面使用mysql命令的时候,能够有这个命令做铺垫。
·
·1. my.cnf配置
·编辑,vim /etc/my.cnf
·在my.cnf中,找到[mysqld],在此下增加如下配置:
·basedir=/usr/local/mysql
·datadir=/usr/local/mysql/data
·character_set_server=utf8
·[client]
·default-character-set=utf8
·最后保存并退出。
·
·2. mysqld配置
·2.1. 拷贝启动文件到/etc/init.d/下并重命令为mysqld
·cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
·
·2.2. 增加执行权限
·chmod 755 /etc/init.d/mysqld
·
·2.3. 检查自启动项列表中没有mysqld
·chkconfig --list mysqld
·
·2.4. 如果没有就添加mysqld
·chkconfig --add mysqld
·
·2.5. 设置开机启动
·chkconfig mysqld on
·
·2.6. 启动测试
·service mysqld start
·
·如图:
·
·说明我们的配置文件成功,mysql彻底安装完成。
·
·1. 修改配置文件my.cnf
·vim /etc/my.cnf
·
·2. 找到[mysqld]在之后添加
·skip-grant-tables
·保存退出
·
·3. 重启mysql服务 service mysqld restart
·重启如图:
·
·4. 直接登陆mysql而不需要密码
·mysql -u root -p (一路直接回车)
·进入后的效果:
·
·
·5. 在mysql中输入
·update mysql.user set authentication_string=password('123456') where user='root';
·
·6. 刷新权限 flush privileges
·如图:
·
·
·7. 退出mysql,到my.cnf中把开始添加的skip-grant-tables注释掉或删掉
·
· 8. 重启mysql服务
·service mysqld restart
·
·9. 登录
·mysql -u root -p
·输入密码,即可。
·如图:
·
·
·完成以上工作后,我们的mysql算是装完了,但是,想让外界可以通过工具连接还需要设置。
·
·
添加防火墙端口:
firewall-cmd --add-port=22/tcp
查看开放的端口:
firewall-cmd --list-ports
·输入你数据库所在服务ip, 数据库密码,上面设置的密码是123456,根据你设置而定。
·
https://www.cnblogs.com/panwenbin-logs/p/8360703.html
https://blog.csdn.net/yhl_jxy/article/details/53534194
https://www.cnblogs.com/dadadechengzi/p/6723686.html
https://jingyan.baidu.com/article/5225f26b0bb45fe6fa0908bc.html
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。