mysql study_MySql study note 1

1.login as root

root@vinco:~#mysql -h locahost -u root -p

Enter password:(*******)

2.show all database

mysql> show databases

-> ;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| phpmyadmin |

+--------------------+

3 rows in set (0.01 sec)

3.select one database of them

mysql> use mysql

Database changed

4.show all tables

mysql> show tables

-> ;

+---------------------------+

| Tables_in_mysql |

+---------------------------+

| columns_priv |

| db |

| event |

| func |

| general_log |

| help_category |

| help_keyword |

| help_relation |

| help_topic |

| host |

| ndb_binlog_index |

| plugin |

| proc |

| procs_priv |

| servers |

| slow_log |

| tables_priv |

| time_zone |

| time_zone_leap_second |

| time_zone_name |

| time_zone_transition |

| time_zone_transition_type |

| user |

+---------------------------+

23 rows in set (0.00 sec)

6. create table

mysql> create table classmates(

-> name char(15),

-> telephone varchar(20),

-> qq varchar(12)

-> );

Query OK, 0 rows affected (0.23 sec)

mysql> show tables

-> ;

+---------------------------+

| Tables_in_mysql |

+---------------------------+

| classmates |

| columns_priv |

| db |

| event |

| func |

| general_log |

| help_category |

| help_keyword |

| help_relation |

| help_topic |

| host |

| ndb_binlog_index |

| plugin |

| proc |

| procs_priv |

| servers |

| slow_log |

| tables_priv |

| time_zone |

| time_zone_leap_second |

| time_zone_name |

| time_zone_transition |

| time_zone_transition_type |

| user |

+---------------------------+

24 rows in set (0.01 sec)

mysql> describe classmates

-> ;

+-----------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-----------+-------------+------+-----+---------+-------+

| name | char(15) | YES | | NULL | |

| telephone | varchar(20) | YES | | NULL | |

| qq | varchar(12) | YES | | NULL | |

+-----------+-------------+------+-----+---------+-------+

3 rows in set (0.15 sec)

7.insert item into the  created table

mysql> insert into classmates values(

-> "vinco","15572762738","910923899"

-> );

Query OK, 1 row affected (0.20 sec)

mysql> insert into classmates values(

-> "zhang","02787617327","1402088466"

-> );

Query OK, 1 row affected (0.00 sec)

mysql> insert into classmates values(

-> "aa","123456465","8763257123"

-> );

Query OK, 1 row affected (0.00 sec)

mysql> select * from classmates;

+-------+-------------+------------+

| name | telephone | qq |

+-------+-------------+------------+

| vinco | 15572762738 | 910923899 |

| zhang | 02787617327 | 1402088466 |

| aa | 123456465 | 8763257123 |

+-------+-------------+------------+

3 rows in set (0.00 sec)

8. update the data in the table

mysql> update classmates set name="alice" where name="aa";

Query OK, 1 row affected (0.42 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from classmates

-> ;

+-------+-------------+------------+

| name | telephone | qq |

+-------+-------------+------------+

| vinco | 15572762738 | 910923899 |

| zhang | 02787617327 | 1402088466 |

| alice | 123456465 | 8763257123 |

+-------+-------------+------------+

3 rows in set (0.00 sec)

9.delete an entry from the table

mysql> delete from classmates where name="alice";

Query OK, 1 row affected (0.05 sec)

mysql> select * from classmates;

+-------+-------------+------------+

| name | telephone | qq |

+-------+-------------+------------+

| vinco | 15572762738 | 910923899 |

| zhang | 02787617327 | 1402088466 |

+-------+-------------+------------+

2 rows in set (0.00 sec)

10. add a new user and grant some privileges to her

mysql> grant select,insert,update,delete on classmates.* to zhang@localhost identified by "zhang";

Query OK, 0 rows affected (0.58 sec)

/* open a new console here now */

zhang@vinco:~o$ whoami

zhang

zhang@vinco:/home/vinco$ mysql -u zhang -h localhost -p

Enter password: (zhang)

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 50

Server version: 5.1.37-1ubuntu5.5 (Ubuntu)

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

mysql>

11. privileges manegment

mysql> grant select,insert,update,delete on classmates.* to zhang@localhost identified by "zhang";

Query OK, 0 rows affected (0.58 sec)

mysql> revoke delete on classmates.* from zhang@localhost ;

Query OK, 0 rows affected (0.00 sec)

mysql> revoke all privileges on classmates.* from zhang@localhost;

Query OK, 0 rows affected (0.00 sec)

12 quit from mysql

mysql> quit

Bye

root@vinco:~#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值