linux中安装mysql
**步骤:**
1)准备工作
①查看CentOS自带的mysql
查看:输入 rpm -qa | grep mysql
![image](//upload-images.jianshu.io/upload_images/5887463-28f7f483414d9da2.png?imageMogr2/auto-orient/strip|imageView2/2/w/498/format/webp)
卸载:将自带的mysql卸载
![image](//upload-images.jianshu.io/upload_images/5887463-ada3cd37b7984a06.png?imageMogr2/auto-orient/strip|imageView2/2/w/487/format/webp)
②查看带有mariadb
查看:[root@fgy src]# rpm -qa|grep mariadb
卸载:[root@fgy src]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
③查找带有mysql的文件及文件夹都删除
查看: find / -name mysql
删除:rm -rf 路径
3)上传Mysql到linux
使用ssh,将本地数据拖到远程普通用户下
4)解压Mysql到/usr/local/下的mysql目录(mysql目录需要手动创建)内
```
cd /usr/local
mkdir mysql
ls
tar -xvf MySQL-5.6.22-1.el6.i686.rpm-bundle.tar -C /usr/local/mysql
```
得到结果:
![image](//upload-images.jianshu.io/upload_images/5887463-438cf988b42d257d.png?imageMogr2/auto-orient/strip|imageView2/2/w/505/format/webp)
5)在/usr/local/mysql下安装mysql
```
//安装依赖
[root@fgy src]# yum install libaio
[root@fgy src]# yum install perl
[root@fgy src]# yum install net-tools
//安装mysql
[root@localhost src]# rpm -ivh mysql-community-common-55.7.29-1.el7.x86_64.rpm
[root@localhost src]# rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm
[root@localhost src]# rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm --nodeps --force
[root@localhost src]# rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm --nodeps --force
```
6)启动mysql
centos7:service mysqld start
centos6:service mysql start
查看启动状态: service mysqld status
![image](//upload-images.jianshu.io/upload_images/5887463-02276634b5e5165c.png?imageMogr2/auto-orient/strip|imageView2/2/w/1128/format/webp)
7)将mysql加到系统服务中并设置开机启动
加入到系统服务:chkconfig --add mysql
自动启动:chkconfig mysql on
8)登录mysql(5.5的版本为空)
mysql安装好后会生成一个临时随机密码,存储位置在/root/.mysql_secret
![image](//upload-images.jianshu.io/upload_images/5887463-ac3fc82837f084e1.png?imageMogr2/auto-orient/strip|imageView2/2/w/717/format/webp)
centos7查看密码: grep password /var/log/mysqld.log
centos6查看密码: cat /root/.mysql.secret
![image](//upload-images.jianshu.io/upload_images/5887463-de785b66d436a1cc.png?imageMogr2/auto-orient/strip|imageView2/2/w/1118/format/webp)
msyql –u root -p
9)修改mysql的密码
必须修改密码,否则会报错
```
mysql> select user();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
```
但是修改密码有要求,必须为8位,并且包含字母、数字、特殊字符,可以修改
```
//修改以下参数只限制了八位
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
//
```
set password = password('123456');
10)开启mysql的远程登录
默认情况下mysql为安全起见,不支持远程登录mysql,所以需要设置开启 远程登录mysql的权限
登录mysql后输入如下命令:
```
grant all privileges on *.* to 'root' @'%' identified by 'root';
flush privileges;
```
其中,root为账号,第二个root为远程数据库密码(12345678)
11)开放Linux的对外访问的端口3306
先查看已经开放的端口:netstat -aptn
![image](//upload-images.jianshu.io/upload_images/5887463-f0604c04871bc50d.png?imageMogr2/auto-orient/strip|imageView2/2/w/1108/format/webp)
再开放:
```
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save ---将修改永久保存到防火墙中
```
![image](//upload-images.jianshu.io/upload_images/5887463-b9405af2d3e75dcb.png?imageMogr2/auto-orient/strip|imageView2/2/w/780/format/webp)
#### 3.Tomcat安装
**步骤:**
1)上传Tomcat到linux上
2)解压Tomcat到/usr/local下
3)开放Linux的对外访问的端口8080
```
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
/etc/rc.d/init.d/iptables save
```
4)启动关闭Tomcat
进入tomcat的bin下启动:./startup.sh
进入tomcat的bin下关闭:./shutdown.sh