一、mysql 创建数据库

mysql密码,默认没有

如果想更改的话, mysqladmin  -uroot   password  root123

登录   : [root@localhost root]#   mysql    -uroot    -proot123

1、创建book数据库

mysql>   create   database   book;
Query OK, 1 row affected (0.08 sec)

2、授权给 lili 用户

mysql>  grant   all   on   book.*   to   lili@localhost   identified   by   "lili123";
Query OK, 0 rows affected (0.06 sec)

mysql> exit
Bye

3、lili登录

创建lili用户

[root@localhost html]#   mysql   -u   lili    -p
Enter password:       (这里输密码)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 3.23.54

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

4、创建book表,添加数据

mysql> use  book;    (先确定要操作的数据库)
Database changed

5、创建book表

mysql> create   table   book(
    -> id   int   not   null,
    -> name   char(20)   not   null,
    -> primary   key(id)
    -> );
Query OK, 0 rows affected (0.08 sec)

6、添加数据

mysql>  insert   into   book   values

-> (1,"语文"),
    -> (2,"数学"),
    -> (3,"英语");
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

(注意:上面操作也可以用sql语句集来执行:   (好处是,去别的机子也可以执行sql语句集 就行,不用从头打过)

[root@localhost html]#  cat  >  lili.sql
use   book;
create   table   book(
    id   int   not   null,
    name   char(20)   not  null,
    primary   key(id)
    );
insert   into  book  values
     (1,"语文",),
     (2,"数学"),
     (3,"英语");

[root@localhost html]# vi  root.sql
create   database   book;
grant   all   on   book.*   to   lili@localhost   identified   by   "lili123" ;

[root@localhost html]# mysql   -u   root   -p   <   root.sql
Enter password:

[root@localhost html]# mysql   -u   lili   -p   <   lili.sql
Enter password:

7、查询表

mysql> select   *   from   book;
+----+--------+
| id | name   |
+----+--------+
|  1 | 语文 |
|  2 | 数学 |
|  3 | 英语 |
+----+--------+

退出mysql
mysql> exit;
Bye

如果想直接命令行查询

[root@localhost root]# echo   "select  *  from  book;" |  mysql  -u  lili  -p  book

Enter password:
id       name
1       语文
2       数学
3       英语

二、在 /var/www/html  中 创建index.php

[root@localhost html]#  vi    index.php

<h1>
<?php
mysql_connect(NULL,"lili","lili123","localhost");
mysql_selectdb("book");
$sql="select * from book";
$res=mysql_query($sql);
while($row=mysql_fetch_row($res)){
print "$row[0] $row[1]<br/>";
} $a=array("阳光","沙滩","海浪","仙人掌");
for($i=0;$i<4;$i++){
print "$a[$i]<br/>";
}
?>
</h1>

在浏览器输入  http://192.168.170.3/  ,  结果如下:

如果想要网格线

<html>
<title>
</title>
<body>
<h1>
<?php
mysql_connect(NULL,"lili","lili123","localhost");
mysql_selectdb("book");
$sql="select * from book";
$res=mysql_query($sql);
print ('<table border=1>');
while($row=mysql_fetch_row($res)){
print ('<tr>');
for($i=0;$i<3;$i++){
print "<td>$row[$i]</td>"; }
print ('</tr>');
} print ('</table>'); $a=array("阳光","沙滩","海浪","仙人掌");
for($i=0;$i<4;$i++){
print "$a[$i]<br/>";
} ?>
</h1>
</body>
</html>

效果如下:

最新文章

  1. java中的final的使用
  2. an excellent capability of C# language and compiler
  3. Json 字符串 转换为 DataTable数据集合
  4. 将C#datagridview控件的数据导出到Excel中
  5. QQ音乐的各种相关API
  6. 学习Slim Framework for PHP v3 (四)--get()是怎么加进去的?
  7. ionic修改loading背景色
  8. C#操作redis代码汇总
  9. Html.DropDownList的用法
  10. 【错排问题】【HDU2048】神、上帝以及老天爷
  11. iOS 热更新插件
  12. sass、less、stylus的安装及使用
  13. TCP/IP协议:OSI七层模型、TCP/IP四层模型的对比
  14. 关于ListView中包含EditText数据复用引起异常的解决方案
  15. Hadoop开启后jps显示只有jps
  16. Kubenetes 核心概念理解
  17. IDEA在同一窗口导入多个项目
  18. unidbgrid 设置 单元格颜色
  19. Linux 小知识翻译 - 「版本号」的命名方式
  20. AI 随机梯度下降(SGD)

热门文章

  1. 【Android】Fragment懒加载和ViewPager的坑
  2. iOS的一些面试题分析总结(0)
  3. 图片上传插件ImgUploadJS:用HTML5 File API 实现截图粘贴上传、拖拽上传
  4. 7.DataAnnotations(数据注解)【Code-First 系列】
  5. customErrors与错误页面
  6. 纯css3天气动画场景特效
  7. C#写爬虫,版本V2.0
  8. 51nod 算法马拉松18 B 非010串 矩阵快速幂
  9. CentOS操作记录
  10. (原)3.1 Zookeeper应用 - Master选举