国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

15、sql語句集,Linux 下PHP查詢mysql

2024-06-28 13:18:55
字體:
來源:轉載
供稿:網友
15、sql語句集,linux 下php查詢MySQL

一、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> exitBye

3、lili登錄

創建lili用戶

[root@localhost html]# mysql -u lili -pEnter 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.sqluse 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.sqlcreate database book;grant all on book.* to lili@localhost identified by "lili123" ;

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

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

7、查詢表

mysql> select * from book;+----+--------+| id | name |+----+--------+| 1 | 語文 || 2 | 數學 || 3 | 英語 |+----+--------+

退出mysqlmysql> exit;Bye

如果想直接命令行查詢

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

Enter password:id name1 語文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/ , 結果如下:

image

如果想要網格線

<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>

效果如下:

image


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 五台县| 阿克苏市| 呼玛县| 彩票| 蓝田县| 沽源县| 溧阳市| 双辽市| 罗甸县| 贵阳市| 河西区| 呼伦贝尔市| 加查县| 高尔夫| 哈密市| 望奎县| 平罗县| 惠东县| 磴口县| 乌兰察布市| 循化| 襄垣县| 亚东县| 三都| 永顺县| 礼泉县| 揭阳市| 呼图壁县| 体育| 宁安市| 房山区| 夹江县| 台中市| 伊宁县| 鲁山县| 墨竹工卡县| 庆云县| 梓潼县| 水富县| 琼海市| 琼海市|