alter是非常強大的一個功能我們可以利用alter來修改數據表表名字體名及一些其它的操作了,下面一起來看看mysql中alter數據表中增加、刪除字段與表名修改的一個例子.
修改刪除mysql數據庫中的數據內容:
[[email protected] ~]# /usr/local/mysql/bin/mysql -uroot -p'admin' #進入mysql
mysql> create database gbk default character set gbk collate gbk_chinese_ci; #建立一個名字叫做gbk的數據庫
mysql> use gbk
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| gbk |
+--------------------+
mysql> show tables;
Empty set (0.00 sec)
mysql> create table test( #建立一個叫做test的數據表
-> id int(4) not null primary key auto_increment,
-> name char(20) not null
-> );
Query OK, 0 rows affected (0.13 sec)
mysql> show tables;
+---------------+
| Tables_in_gbk |
+---------------+
| test |
+---------------+
1 row in set (0.00 sec)
mysql> insert into test(id,name) values(1,'zy'); #插入部分內容
mysql> insert into test(id,name) values(2,'binghe');
mysql> insert into test(id,name) values(3,'zilong');
mysql> insert into test(id,name) values(4,'feng');
mysql> select * from test; #檢索整個test表
+----+--------+
| id | name |
+----+--------+
| 1 | zy |
| 2 | binghe |
| 3 | zilong |
| 4 | feng |
+----+--------+
4 rows in set (0.00 sec)
[[email protected] ~]# /usr/local/mysql/bin/mysqldump -uroot -p'admin' -B gbk >/tmp/gbk.sql #備份gbk數據庫
mysql> update test set name = 'zy' ; #未定義
mysql> select * from test; #
+----+------+
| id | name |
+----+------+
| 1 | zy |
| 2 | zy |
| 3 | zy |
| 4 | zy |
+----+------+
[[email protected] ~]# /usr/local/mysql/bin/mysql -uroot -p'admin' mysql> use gbk
mysql> select * from test;
+----+--------+
| id | name |
+----+--------+
| 1 | zy |
| 2 | binghe |
| 3 | zilong |
| 4 | feng |
+----+--------+
mysql> update test set name = 'yadianna' where id =1;
mysql> select * from test;
+----+----------+
| id | name |
+----+----------+
| 1 | yadianna |
| 2 | binghe |
| 3 | zilong |
| 4 | feng |
+----+----------+
mysql> update test set id = 999 where name ='yadianna';
mysql>
新聞熱點
疑難解答
圖片精選