红联Linux门户
Linux帮助

MySQL的使用

发布时间:2011-11-19 22:26:29来源:红联作者:专攻Linux/ARM
启动mysqld,并以root帐号登录MySQL
[root@lzf yh1]# service mysqld start
正在启动 mysqld: [确定]
[root@lzf yh1]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@lzf yh1]# mysql -u root -p
Enter password: (root帐号没有密码,直接按回车)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.58 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
浏览已存在的数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| rsglxt |
| test |
+--------------------+
4 rows in set (0.09 sec)

mysql>
创建一个名为rsglxt的数据库
mysql> create database rsglxt;
选中数据库rsglxt
mysql> use rsglxt
新建一个员工信息表employees
mysql> creat table employees(
-> ID carchar(4) NOT NULL,
-> username varchar(8),
-> sex char(2),
-> age int(2),
-> card varchar(20),
-> phone varchar(10),
-> depID char(2),
-> position varchar(20),
-> primary key(ID));
查看employees表中字段的定义
mysql> describe employees;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| ID | varchar(4) | NO | PRI | NULL | |
| username | varchar(8) | YES | | NULL | |
| sex | char(2) | YES | | NULL | |
| age | int(2) | YES | | NULL | |
| card | varchar(20) | YES | | NULL | |
| phone | varchar(10) | YES | | NULL | |
| depID | char(2) | YES | | NULL | |
| position | varchar(20) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
8 rows in set (0.00 sec)

mysql>
向表中添加几条记录
mysql> insert into employees values(
-> "0002","李四","女",29,"315246197803261475","95175346","西","职员");
Query OK, 1 row affected, 2 warnings (0.00 sec)

mysql>
查看表及所在记录
mysql> show tables;
+------------------+
| Tables_in_rsglxt |
+------------------+
| employees |
+------------------+
1 row in set (0.00 sec)

mysql> select *from employees;
+------+----------+------+------+--------------------+------------+-------+----------+
| ID | username | sex | age | card | phone | depID | position |
+------+----------+------+------+--------------------+------------+-------+----------+
| 0001 | 张三 |
文章评论

共有 2 条评论

  1. yehua243 于 2012-06-16 14:51:40发表:

    luo过看看

  2. spworks 于 2011-11-20 08:54:12发表:

    顺路学习