|
4#
楼主 |
发表于 2009-11-9 11:00:24
|
只看该作者
Mysql 的基本操作
1. 修改用户密码
因为root 用户初始没有密码 所以直接修改
[root@localhost bin]# ./mysqladmin -u root -password 123456
为已有密码的用户修改密码
[root@localhost bin]# ./mysqladmin -u root -p111111 password 123456
2. 查看数据库
在进入数据库后输入 show databases; (注意分号)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| redmoonoa |
| test |
+--------------------+
4 rows in set (0.07 sec)
3. 进入数据库
mysql> use test;
Database changed
4. 查看数据库中的表
mysql> show tables;
Empty set (0.00 sec)
5. 建数据库、表、
mysql> create database mysql_test
-> ;
Query OK, 1 row affected (0.02 sec)
mysql> use mysql_test;
Database changed
mysql> create table users ( id int(3) auto_increment not null primary key, namechar(10) not null, pwd char(10) not null);
Query OK, 0 rows affected (0.04 sec)
验证:
mysql> describe users //查看表结构
-> ;
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| id | int(3) | NO | PRI | NULL | auto_increment |
| name | char(10) | NO | | NULL | |
| pwd | char(10) | NO | | NULL | |
+-------+----------+------+-----+---------+----------------+
插入数据:
mysql> insert into users(name,pwd) values('user1','123456');
Query OK, 1 row affected (0.00 sec)
mysql> insert into users(name,pwd) values('admin','123456');
Query OK, 1 row affected (0.01 sec)
验证:
mysql> select * from users
-> ;
+----+-------+--------+
| id | name | pwd |
+----+-------+--------+
| 1 | user1 | 123456 |
| 2 | admin | 123456 |
+----+-------+--------+
2 rows in set (0.00 sec) |
|