15, SQL statement set, Linux PHP query MySQL

Source: Internet
Author: User
Tags create index mysql create mysql create database lost password

First, MySQL CREATE database

MySQL password, default no

If you want to change it, mysqladmin-uroot password root123

Login: [[email protected] root]# mysql-uroot-proot123

1. Create book Database

mysql> CREATE DATABASE book;
Query OK, 1 row affected (0.08 sec)

2, authorized to Lili users

Mysql> Grant all on book.* to [e- Mail protected] identified by "lili123";
Query OK, 0 rows affected (0.06 sec)

Mysql> exit
Bye

3, Lili Login

Create Lili User

[Email protected] html]# mysql-u lili-p
Enter Password: (lost password here)
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. Create Book table, add data

mysql> use book ; (First determine the database to be manipulated)
Database changed

5. Create Book table

Mysql> CREATE TABLE book (
-ID int NOT NULL,
, Name char (a) is not NULL,
-primary KEY (ID)
);
Query OK, 0 rows affected (0.08 sec)

6. Add Data

mysql> insert into book values

(1, "language"),
(2, "mathematics"),
(3, "English");
Query OK, 3 Rows Affected (0.00 sec)
Records:3 duplicates:0 warnings:0

(Note: The above actions can also be executed with the SQL statement set: (The advantage is that the other machine can also execute the SQL statement set on the line, do not have to play from scratch )

[Email protected] html]# cat > Lili.sql
Use book;
CREATE TABLE book (
ID int NOT NULL,
Name Char (a) is not NULL,
Primary KEY (ID)
);
INSERT INTO book values
(1, "language",),
(2, "mathematics"),
(3, "English");

[Email protected] html]# VI root.sql
Create database book;
Grant all on book.* to [e-mail protected] identified by "lili123";

[Email protected] html]# mysql-u root-p < Root.sql
Enter Password:

[Email protected] html]# mysql-u lili-p < Lili.sql
Enter Password:

7. Enquiry Form

Mysql> SELECT * from book;
+----+--------+
| ID | name |
+----+--------+
| 1 | language |
| 2 | Math |
| 3 | English |
+----+--------+

Quit MySQL
Mysql> exit;
Bye

Second, create index.php in/var/www/html

[Email protected] html]# VI index.php

php   mysql_connect (NULL,"Lili", "lili123", "localhost");   Mysql_selectdb ("book");   $sql= "SELECT * from book";   $res=mysql_query ($sql);     while ($row =mysql_fetch_row ($res)) {      "$row [0] $row [1]<br/>";              }      $a=array ("Sunshine", "Beach", "surf", "Cactus");        for ($i =0; $i <4; $i + +)        {"$a [$i]<br/>";              }? >

In the browser input http://192.168.170.3/, the results are as follows:

If you want a grid line

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 ("Sunshine", "Beach", "surf", "Cactus");  for($i =0; $i <4; $i + +) {print"$a [$i]<br/>"; }?>
  

The effect is as follows:

15, SQL statement set, Linux PHP query MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.