Linux · 2008-12-11

学习mysql数据库

我的测试机上没有设root密码,设置下(内网机器,出不了外网,所以也没去动)。
设置root密码的命令为

set password for ‘root’@’localhost’=password(‘你的密码’);


root@debian:~# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.0.32-Debian_7etch6-log Debian etch distribution

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

mysql> set password for ‘root’@’localhost’=password(‘123456’);
Query OK, 0 rows affected (0.22 sec)


创建数据库 名字为man.

mysql> create database man;
Query OK, 1 row affected (0.07 sec)

使用man这个数据库.

mysql> use man;
Database changed

创建数据库的表

mysql> create table man (
-> id int unique not null,
-> name varchar(40),
-> age varchar(50),
-> primary key(id)
-> );
Query OK, 0 rows affected (0.00 sec)

增加表单内容

mysql> INSERT INTO man VALUES(1,'Brian','28');     
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO man VALUES(2,'Billy','26');        
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO man VALUES(3,'Dimitri','26');       
Query OK, 1 row affected (0.01 sec)


mysql> INSERT INTO man VALUES(4,'ross','30');            
Query OK, 1 row affected (0.00 sec)

定义出这么个表格,ID,姓名,年龄。

mysql> select * from man;
+----+---------+------+
| id | name    | age  |
+----+---------+------+
|  1 | Brian   | 28   | 
|  2 | Billy   | 26   | 
|  3 | Dimitri | 26   | 
|  4 | ross    | 30   | 
+----+---------+------+
4 rows in set (0.00 sec)



mysql学习中…