一、一台主机安装mysql数据库
1、安装软件包
[root@localhost ~]# yum -y install mariadb-server mariadb
2、开启服务
[root@localhost ~]# systemctl start mariadb
3、查看是否有3306端口
[root@localhost ~]# netstat -anpt Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:*
4、登录数据库
[root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 2 Server version: 5.5.41-MariaDB MariaDB Server Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [(none)]>
建一个数据库
MariaDB [(none)]> create database slsaledb; Query OK, 1 row affected (0.00 sec)
给数据库授权
MariaDB [(none)]> grant all on slsaledb.* to admin@'%' identified by '123123'; Query OK, 0 rows affected (0.00 sec)
%:连接可以来源于任何地址
刷新一下授权表
MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)
退出
MariaDB [(none)]> exit
Bye
[root@localhost ~]#
5、向数据库中导入数据
添加一个*.sql的文件
[root@localhost ~]# rz -E rz waiting to receive. [root@localhost ~]# ls anaconda-ks.cfg nginx-1.16.0.tar.gz slsaledb-2014-4-10.sql
将文件导入数据库
[root@localhost ~]# mysql -uroot < slsaledb-2014-4-10.sql
二、将安装tomcat的主机连接到数据库
1、修改网页文件下的内容
[root@localhost ~]# ls /web/webapp/ index.jsp SLSaleSystem [root@localhost ~]# ls /web/webapp/SLSaleSystem/ logs META-INF statics WEB-INF [root@localhost ~]# ls /web/webapp/SLSaleSystem/WEB-INF/ classes lib pages web.xml [root@localhost ~]# ls /web/webapp/SLSaleSystem/WEB-INF/classes/ applicationContext-mybatis.xml mybatis-config.xml jdbc.properties org log4j.properties spring-servlet.xml [root@localhost ~]# vim /web/webapp/SLSaleSystem/WEB-INF/classes/jdbc.properties
[root@localhost ~]# vim /web/webapp/SLSaleSystem/WEB-INF/classes/jdbc.properties
url=jdbc:mysql://192.168.200.111:3306/slsaledb?useUnicode=true&characterEncoding=UTF-8 //数据库主机的IP uname=admin //数据库的用户名 password=123123 //数据库的密码
测试(用户名admin,密码123456登录)
如果在测试过程中,nginx主机登录的时候总是跳转,登陆不进去,就需要在主配置文件中添加如下:
upstream tomcat_server { ip_hash; //将网页固定到当前页执行 server 192.168.200.112:8080 weight=1; server 192.168.200.113:8080 weight=1; } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; proxy_set_header Host $http_host; proxy_pass http://tomcat_server; }