从Mysql白丁到Mysql达人系列培训课程一
Ice-Spring
http://space.itpub.net/28985005
友情传达:
本课程所有环境都是基于linux平台,试验与事例都是在linux环境下演示。在Linux系统上我们用Mysql用户安装好Mysql数据库,使用和维护Mysql数据库的用户必须用Mysql。
[root@crmtestdb root]# su - mysql
[root@crmtestdb mysql]$ mysql -u root -h 127.0.0.1
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.45-community MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
如果以管理员身份登陆,登录方式为:
mysql -u root -p
输入密码后登陆到mysql数据库,查看有哪些数据库,使用如下的命令:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| glj |
+--------------------+
4 rows in set (0.00 sec)
选择数据库进行操作,用如下命令:
mysql> use test
Database changed
mysql>
创建一个数据库baidindaren
mysql> CREATE DATABASE baidindaren
选择所创建的数据库 :
mysql> USE baidindaren
Database changed
创建表:
mysql> create table User (UserId int auto_increment not null primary key, UserName varchar(50) not null);
Query OK, 0 rows affected (0.08 sec)
查看表定义结构:
mysql> desc User
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| UserId | int(11) | NO | PRI | NULL | auto_increment |
| UserName | varchar(50) | NO | | NULL | |
+--------------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
往表中加入记录 :
我们先用SELECT命令来查看表中的数据:
mysql> select * from User;
Empty set (0.00 sec)
这说明刚才创建的表还没有记录。
加入一条新记录:
mysql> insert into User values (101,’glj’);
Query OK, 1 row affected (0.05 sec)
再用上面的SELECT命令看看发生了什么变化。
删除表:
DROP TABLE User;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28985005/viewspace-765020/ ,如需转载,请注明出处,否则将追究法律责任。