设为首页 加入收藏

TOP

MySQL数据库安装、配置及基本操作(二)
2015-07-24 12:03:29 来源: 作者: 【 】 浏览:34
Tags:MySQL 数据库 安装 配置 基本操作
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database yr; Query OK, 1 row affected (0.00 sec) mysql> exit Bye [root@localhost mysql]# 首先,我们用root账户登录数据库,可以看到mysql> 命令提示符号,执行创建数据库命令create database name; 得到创建成功消息,退出数据库使用命令exit。 现在,我们可以在/var/lib.mysql下面看到已经创建的数据库yr:
[root@localhost mysql]# ls -l
total 20504
-rw-r--r--. 1 root  root     10717 May 13 10:34 create
-rw-rw----. 1 mysql mysql 10485760 May 13 10:27 ibdata1
-rw-rw----. 1 mysql mysql  5242880 May 13 10:27 ib_logfile0
-rw-rw----. 1 mysql mysql  5242880 May 13 10:27 ib_logfile1
drwx------. 2 mysql mysql     4096 May 13 10:27 mysql
srwxrwxrwx. 1 mysql mysql        0 May 13 10:27 mysql.sock
drwx------. 2 mysql mysql     4096 May 13 10:27 test
drwx------. 2 mysql mysql     4096 May 13 14:41 yr
[root@localhost mysql]# 
(2)建表并添加数据 下面,再次登录MySQL我们在上面创建的数据库中建表,并添加几条数据:
[root@localhost mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> use yr;
Database changed
mysql> create table user(
    -> Id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY,
    -> Name VARCHAR(50),
    -> age INTEGER);
Query OK, 0 rows affected (0.07 sec)

mysql> 

至此,yr数据库中便创建成功一个user表,有Id 、 Name 、age三个属性,其中Id为主键。 添加并查询数据:
mysql> insert into user(Id , Name , age)values(1,"aa",20);
Query OK, 1 row affected (0.10 sec)

mysql> insert into user(Id , Name , age)values(2,"bb",21);
Query OK, 1 row affected (0.00 sec)
mysql> select Id , Name , age from user;
+----+------+------+
| Id | Name | age  |
+----+------+------+
|  1 | aa   |   20 |
|  2 | bb   |   21 |
+----+------+------+
(3)从数据库表中删除数据 下面我们删除一条Id=1的数据:
mysql> delete from user where Id=1;
Query OK, 1 row affected (0.05 sec)

mysql> select Id , Name , age from user;
+----+------+------+
| Id | Name | age  |
+----+------+------+
|  2 | bb   |   21 |
+----+------+------+
1 row in set (0.00 sec)

mysql> 

(4)删除数据库表和数据库 删除数据库表和数据库使用drop命令:
mysql> drop table user;
Query OK, 0 rows affected (0.02 sec)
mysql> drop database yr;
Query OK, 0 rows affected (0.28 sec)

mysql> exit
Bye
[root@localhost mysql]# ll
total 20500
-rw-r--r--. 1 root  root     10717 May 13 10:34 create
-rw-rw----. 1 mysql mysql 10485760 May 13 10:27 ibdata1
-rw-rw----. 1 mysql mysql  5242880 May 13 10:27 ib_logfile0
-rw-rw----. 1 mysql mysql  5242880 May 13 10:27 ib_logfile1
drwx------. 2 mysql mysql     4096 May 13 10:27 mysql
srwxrwxrwx. 1 mysql mysql        0 May 13 10:27 mysql.sock
drwx------. 2 mysql mysql     4096 May 13 10:27 test
[root@localhost mysql]# 

以上是linux 系统有关mysql安装、配置以及使用的全部内容。
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇win764位安装mysql 下一篇Mysql常用命令行大全

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: