2021-05-19

linux安装mysql

使用xftp5上传mysql到linux服务器

在这里插入图片描述

在usr/local目录下创建mysql文件夹

创建文件夹命令 mkdir mysql

[root@centos ~]# cd /usr/local
[root@centos local]# mkdir mysql

ls查看是否创建成功

[root@centos local]# ls
bin etc games include java jdk1.8.0_212 lib lib64 libexec mysql sbin share src

回到root目录下 将压缩包移动到urs/local/mysql文件夹下

[root@centos local]# ls
bin etc games include java jdk1.8.0_212 lib lib64 libexec mysql sbin share src

查看是否移动到mysql文件夹下:

[root@centos ~]# cd /usr/local/mysql
[root@centos mysql]# ls
MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar

查看系统自带的mysql :rpm -qa | grep -i mysql

[root@centos mysql]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-7.el6.x86_64
mysql80-community-release-el7-3.noarch

卸载系统自带的mysql

[root@centos mysql]# rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64

[root@centos ~]# rpm -e --nodeps mysql80-community-release-el7-3.noarch
warning: erase unlink of /etc/yum.repos.d/mysql-community.repo failed: 没有那个文件或目录
warning: erase unlink of /etc/yum.repos.d/mysql-community-source.repo failed: 没有那个文件或目录

再用rpm -qa | grep mysql命令没有显示mysql,表示卸载干净了

检查mysql用户组、用户是否存在,不存在则创建

[root@centos7 src]# cat /etc/group | grep mysql
[root@centos7 src]# cat /etc/passwd | grep mysql
[root@centos7 src]# groupadd mysql
[root@centos7 src]# useradd -g mysql mysql

解压mysql压缩包:

[root@centos mysql]# tar -xvf MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar -C /usr/local/mysql
MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-devel-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-compat-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-embedded-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-test-5.6.26-1.linux_glibc2.5.x86_64.rpm
[root@centos mysql]# ls
MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar MySQL-devel-5.6.26-1.linux_glibc2.5.x86_64.rpm MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm MySQL-shared-compat-5.6.26-1.linux_glibc2.5.x86_64.rpm
MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm MySQL-embedded-5.6.26-1.linux_glibc2.5.x86_64.rpm MySQL-shared-5.6.26-1.linux_glibc2.5.x86_64.rpm MySQL-test-5.6.26-1.linux_glibc2.5.x86_64.rpm

安装mysql服务端:

[root@centos ~]# cd /usr/local/mysql
[root@centos mysql]# rpm -ivh MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm

安装mysql客户端:

[root@centos mysql]# rpm -ivh MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm

启动mysql

[root@centos mysql]# service mysql start

将mysql加到系统服务中并设置开机启动

[root@centos mysql]# chkconfig --add mysql
[root@centos mysql]# chkconfig mysql on

查看mysql默认密码;

[root@centos ~]# cat /root/.mysql_secret

圈起来的是初始化的密码,第一次登陆的时候用这个登陆

设置root密码

mysql> set password = password(‘root’);
Query OK, 0 rows affected (0.00 sec)

退出mysql

mysql> quit
Bye

使用新密码root登录

[root@centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.26 MySQL Community Server (GPL)

Copyright © 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

开启mysql的远程登录

默认情况下mysql为安全起见,不支持远程登录mysql,所以需要设置开启 远程登录mysql的权限

登录mysql后输入如下命令:

mysql> grant all privileges on . to ‘root’ @‘%’ identified by ‘root’;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

退出mysql :

mysql> quit
Bye

在root目录下 开放Linux的对外访问的端口3306

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

/etc/rc.d/init.d/iptables save —将修改永久保存到防火墙中

[root@centos ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
[root@centos ~]# /etc/rc.d/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]
[root@centos ~]#

用Navicat远程连接成功:

配置tomcat

1)上传Tomcat到linux上移动到usr/local文件夹下

[root@centos ~]# mv ./apache-tomcat-7.0.47.tar.gz /usr/local

2)解压Tomcat到/usr/local下

[root@centos ~]# cd /usr/local
[root@centos local]# ls
apache-tomcat-7.0.47.tar.gz bin etc games include java jdk1.8.0_212 lib lib64 libexec mysql sbin share src
[root@centos local]# tar -zxvf apache-tomcat-7.0.47.tar.gz

3)开放Linux的对外访问的端口8080

/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

/etc/rc.d/init.d/iptables save

[root@centos /]# cd /root
[root@centos ~]# /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
[root@centos ~]# /etc/rc.d/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]

4)启动关闭Tomcat

进入tomcat的bin下启动:./startup.sh

进入tomcat的bin下关闭:./shutdown.sh

localhost:8080测试tomcat是否启动成功:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_43186009

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值