您好,登錄后才能下訂單哦!
下文內(nèi)容主要給大家?guī)?lái)mysql舉例分析,這里所講到的知識(shí),與書籍略有不同,都是億速云專業(yè)技術(shù)人員在與用戶接觸過(guò)程中,總結(jié)出來(lái)的,具有一定的經(jīng)驗(yàn)分享價(jià)值,希望給廣大讀者帶來(lái)幫助。
mysql安裝不介紹,mysql -uroot -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.02 sec)
創(chuàng)建表
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
創(chuàng)建數(shù)據(jù)庫(kù)管理用戶
mysql> *grant all on publications. to 'huang'@'localhost' identified by "123456";
Query OK, 0 rows affected (0.00 sec)
更新權(quán)限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
創(chuàng)建表 查看表
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)
再次創(chuàng)建表,增加id選項(xiàng)
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選項(xiàng)
mysql> alter table classics drop id;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
表中插入數(shù)據(jù)
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)
對(duì)于以上關(guān)于mysql舉例分析,如果大家還有更多需要了解的可以持續(xù)關(guān)注我們億速云的行業(yè)推新,如需獲取專業(yè)解答,可在官網(wǎng)聯(lián)系售前售后的,希望該文章可給大家?guī)?lái)一定的知識(shí)更新。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。