Your first database

Now that we have PHP running properly and have created our first script, let's create our first database and see what we can do with it. Drop to console and type in the following command:

mysqladmin -uroot create learndb

This creates a database named "learndb" for us to use. Here we have assumed that you are root user. If you are logged in as another user, just use the command mysqladmin -uusername -pyourpassword create learndb, replacing username and yourpassword with your username and password respectively. If you are hosting your site through a hosting company, you probably don't have permission to run mysqladmin. In this case, you have to ask your server administrator to create the database for you.

Next we will create tables in this database and enter some information. Go to the console. Type:

mysql

You should see something like:

Welcome to MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 to server version 3.22.34

Type 'help' for help.

Type:

CONNECT learndb

CREATE TABLE personnel

id int NOT NULL AUTO_INCREMENT, firstname varchar(25), lastname varchar(20), nick varchar(12), email varchar(35), salary int,

PRIMARY KEY (id),

UNIQUE id (id)

INSERT INTO personnel VALUES ('1','John','Lever','John', 'john@everywhere.net','75000');

INSERT INTO personnel VALUES ('2','Camilla','Anderson','Rose', 'rose@flower.com','66 000');

This creates a table with 5 fields and puts some information in it.

root@Shogan: /root

  • w!
  • File Session^ Options Help
  • X

[root@Shogan /root]# mysqladmin -uroot create learndb Database "learndb" created* [root@Shogan /root]# mysql

Welcome to the MySQL monitor♦ Commands end with ; or \g+ Your MySQL connection id is 3 to server version: 3*22+32

Type 'help' for help*

ysql> CONNECT learndb Connection id: 4 Current database: learndb mysql> CREATE TABLE personnel

  • gt; (
  • gt; id int NOT NULL AUTO_INCREMENT, -> fi rstnam e v archar(25), -> lastname varchar(20), -> nick varchar(12), -> email varchar(35), -> salary int, -> PRIMARY KEY(id), -> UNIQUE id (id) -> );

Query OK, 0 rows affected <0+00 sec) mysql> |

0 0

Post a comment

  • Receive news updates via email from this site