Centos7搭建需要mysql的网站

1.在centos7上安装好http、php、php-mysql服务

php-mysql是用来链接的工具

2.在centos5上yum安装mysql

注意在搭建本地yum源时把校验关闭,不然安装不上

[c5-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
        file:///media/cdrom/
        file:///media/cdrecorder/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-beta
[root@localhost yum.repos.d]# yum install mysql-server -y

3.启动mysql

[root@localhost yum.repos.d]# service mysqld restart

4.进入sql并为centos7创建用户去连接

mysql> create user 'lt'@'192.168.165.134' identified by '123456'; 

lt为用户名,@后的是远端的ip地址,identified是密码

create database xyq;   

创建数据库,名称为xyq

mysql> grant all privileges on xyq.* to 'lt'@'192.168.165.134'; 

为lt这个用户添加权限,*表示全部权限

5.给xyq添加表

mysql> use xyq

进去xyq表格

mysql> -- 数据库: `lrfbeyond_demo`
mysql> --
SERT INTO `notes` (`id`, `content`, `color`, `xyz`, `name`, `addtime`) VALUES
(1, 'jQuery实现拖动层。。。', 'yellow', '584|95|22', 'helloweba', '2011-03-21 10:06:22'),
(2, 'Ajax即时更新保存拖动后的位置。', 'blue', '374|192|24', 'fei', mysql> 
mysql> -- --------------------------------------------------------
mysql> 
mysql> --
mysql> -- 表的结构 `notes`
mysql> --
mysql> 
mysql> CREATE TABLE IF NOT EXISTS `notes` (
    ->   `id` int(11) NOT NULL auto_increment,
    ->   `content` varchar(200) NOT NULL,
    ->   `color` enum('yellow','blue','green') NOT NULL default 'yellow',
    ->   `xyz` varchar(100) default NULL,
    ->   `name` varchar(30) default NULL,
    ->   `addtime` datetime default NULL,
    ->   PRIMARY KEY  (`id`)
    -> ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
Query OK, 0 rows affected (0.01 sec)

mysql> 
mysql> --
mysql> -- 导出表中的数据 `notes`
mysql> --
mysql> 
mysql> INSERT INTO `notes` (`id`, `content`, `color`, `xyz`, `name`, `addtime`) VALUES
    -> (1, 'jQuery实现拖动层。。。', 'yellow', '584|95|22', 'helloweba', '2011-03-21 10:06:22'),
    -> (2, 'Ajax即时更新保存拖动后的位置。', 'blue', '374|192|24', 'fei', '2011-03-21 10:09:25'),
    -> (3, 'CSS实现层的位置', 'green', '372|40|25', 'angel', '2011-03-21 10:12:17'),
    -> (4, '测试一条啊', 'green', '320|112|25', '月光光', '2011-03-28 12:57:53'),
    -> (5, '测试一是的 而非', 'blue', '339|212|27', '月光光', '2011-03-28 13:03:10');
Query OK, 5 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0
mysql> -- phpMyAdmin SQL Dump
mysql> -- version 3.4.10.1
mysql> -- http://www.phpmyadmin.net
mysql> --
mysql> -- 主机: localhost
mysql> -- 生成日期: 2015052623:59
mysql> -- 服务器版本: 5.5.20
mysql> -- PHP 版本: 5.3.10
mysql> 
mysql> SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
Query OK, 0 rows affected (0.00 sec)

mysql> SET time_zone = "+00:00";
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> 
mysql> /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET NAMES utf8 */;
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> --
mysql> -- 数据库: `demo`
mysql> --
mysql> 
mysql> -- --------------------------------------------------------
mysql> 
mysql> --
mysql> -- 表的结构 `wishing_wall`
mysql> --
mysql> 
mysql> CREATE TABLE IF NOT EXISTS `wishing_wall` (
    ->   `id` int(11) NOT NULL AUTO_INCREMENT,
    ->   `content` varchar(200) NOT NULL,
    ->   `color` int(3) DEFAULT '1',
    ->   `xyz` varchar(100) DEFAULT NULL,
    ->   `name` varchar(30) DEFAULT NULL,
    ->   `addtime` datetime DEFAULT NULL,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
Query OK, 0 rows affected (0.00 sec)

mysql> /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Query OK, 0 rows affected (0.00 sec)

6。把网站放入centos里面,并修改connect

<?php
$host="192.168.165.136";      #远端ip地址#
$db_user="lt";                #我们建立的用户名#
$db_pass="123456";            #建立的密码#
$db_name="xyq";               #建立的表名#
$timezone = "Asia/Shanghai";

$link=mysql_connect($host,$db_user,$db_pass);
mysql_select_db($db_name,$link);
mysql_query("SET names UTF8");

header("Content-Type: text/html; charset=utf-8");
date_default_timezone_set($timezone); //北京时间
?>
~       

7.成功界面

 

posted @ 2016-10-24 15:56  liutao97  阅读(453)  评论(0编辑  收藏  举报