首页 > 数据库技术 > 详细

mysql小示例

时间:2019-08-10 23:29:27      阅读:147      评论:0      收藏:0      [点我收藏+]
mysql安装不介绍,mysql -uroot -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.02 sec)
创建表
mysql> create database publications;
Query OK, 1 row affected (0.00 sec)
查看表并使用
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| publications |
| test |
+--------------------+
5 rows in set (0.00 sec)

mysql> use publications;
Database changed
创建数据库管理用户
mysql> *grant all on publications. to ‘huang‘@‘localhost‘ identified by "123456";
Query OK, 0 rows affected (0.00 sec)
更新权限
mysql>
flush privileges;
Query OK, 0 rows affected (0.00 sec)
创建表 查看表
mysql>
create table classics(author varchar(128), title varchar(128), type varchar(16), year char(4));**
Query OK, 0 rows affected (0.01 sec)

mysql> desc classics;
+--------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+-------+
| author | varchar(128) | YES | | NULL | |
| title | varchar(128) | YES | | NULL | |
| type | varchar(16) | YES | | NULL | |
| year | char(4) | YES | | NULL | |
+--------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
删除表
mysql> drop table classics;
Query OK, 0 rows affected (0.00 sec)

再次创建表,增加id选项
mysql> create table classics(author varchar(128), title varchar(128), type varchar(16), year char(4),id INT unsigned not null auto_increment key)ENGINE MyISAM;
Query OK, 0 rows affected (0.01 sec)
删除id选项
mysql> alter table classics drop id;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0

表中插入数据
mysql> insert into classics(author,title,type,year)
-> values("mark twain","muguangzhicheng",‘fiction‘,"1876");

Query OK, 1 row affected (0.00 sec)

mysql> insert into classics(author,title,type,year) values("frank hello","xianglongshibazhang",‘fiction‘,"1856");
Query OK, 1 row affected (0.00 sec)

mysql> insert into classics(author,title,type,year) values("world go","shgendiaoxialv",‘play‘,"1841");
Query OK, 1 row affected (0.00 sec)

mysql> insert into classics(author,title,type,year) values("nale","xiakexing",‘play‘,"1541");
Query OK, 1 row affected (0.00 sec)

mysql> select * from classics;
+-------------+---------------------+---------+------+
| author | title | type | year |
+-------------+---------------------+---------+------+
| mark twain | muguangzhicheng | fiction | 1876 |
| frank hello | xianglongshibazhang | fiction | 1856 |
| world go | shgendiaoxialv | play | 1841 |
| nale | xiakexing | play | 1541 |
+-------------+---------------------+---------+------+
4 rows in set (0.00 sec)

更改表名称
mysql> alter table classics rename pre1900;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+------------------------+
| Tables_in_publications |
+------------------------+
| pre1900 |
+------------------------+
1 row in set (0.00 sec)

mysql小示例

原文:https://blog.51cto.com/13069490/2428421

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!