日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

15、sql语句集,Linux 下PHP查询mysql

發(fā)布時(shí)間:2024/4/15 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 15、sql语句集,Linux 下PHP查询mysql 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、mysql 創(chuàng)建數(shù)據(jù)庫

mysql密碼,默認(rèn)沒有

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

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

1、創(chuàng)建book數(shù)據(jù)庫

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

?

2、授權(quán)給 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登錄

創(chuàng)建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、創(chuàng)建book表,添加數(shù)據(jù)

mysql> use? book;??? (先確定要操作的數(shù)據(jù)庫)
Database changed

?

5、創(chuàng)建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、添加數(shù)據(jù)

mysql>? insert?? into?? book?? values

??? -> (1,"語文"),
??? -> (2,"數(shù)學(xué)"),
??? -> (3,"英語");
Query OK, 3 rows affected (0.00 sec)
Records: 3? Duplicates: 0? Warnings: 0

?

(注意:上面操作也可以用sql語句集來執(zhí)行: ? (好處是,去別的機(jī)子也可以執(zhí)行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,"數(shù)學(xué)"),
???? (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 | 數(shù)學(xué) |
|? 3 | 英語 |
+----+--------+

?

退出mysql
mysql> exit;
Bye

?

如果想直接命令行查詢

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

Enter password:
id ? ? ? name
1 ? ? ? 語文
2 ? ? ? 數(shù)學(xué)
3 ? ? ? 英語

?

二、在 /var/www/html? 中 創(chuàng)建index.php

[root@localhost html]#? vi??? index.php

<h1> <?phpmysql_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/? ,? 結(jié)果如下:

?

如果想要網(wǎng)格線

<html> <title> </title> <body> <h1> <?phpmysql_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>

效果如下:

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/weiapro/p/4765149.html

總結(jié)

以上是生活随笔為你收集整理的15、sql语句集,Linux 下PHP查询mysql的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。