Now you can Subscribe using RSS

Submit your Email

2017/10/17

Linux Ubuntu 操作 MySQL

asd
安裝好 MySQL 並且登入
使用以下指令可以查看目前有哪些數據庫
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

使用以下指令也是一樣結果
mysql> show schemas;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
這些表示安裝好之後系統自帶databases
選擇數據庫並顯示有哪些表
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

建立一個新的 databases 並且查看是否建立
mysql> create database test;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.00 sec)

選擇新建立的 databases 建立一張 table 並且查看是否建立成功
mysql> use test
Database changed
mysql> create table mytable(id int primary key,name varchar(20) not null);
Query OK, 0 rows affected (0.02 sec)

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

建立兩筆數據到 table 中
mysql> insert into mytable values (1,'Tom');
Query OK, 1 row affected (0.00 sec)

mysql> insert into mytable values (2,'Amy');
Query OK, 1 row affected (0.01 sec)

查詢建立的數據
mysql> select * from mytable;
+----+------+
| id | name |
+----+------+
|  1 | Tom  |
|  2 | Amy  |
+----+------+
2 rows in set (0.00 sec)

其實發現進入 mysql 後所有的操作都是要使用 sql 語法進行
以上就是間單的 mysql 操作

0 意見:

張貼留言

Coprights @ 2016, Blogger Templates Designed By Templateism | Templatelib