1.链接:
mysql -h localhost -u root -p
然后输入密码就能登录mysql
2.建立数据库:
CREATEDATABASE tutorial;
显示数据库
show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| GoodByeDealer |
| iWebShop |
| invo |
| laravel5 |
| mysql |
| performance_schema |
| prestashop |
| test |
| tutorial |
+--------------------+
10 rows in set (0.00 sec)
mysql>
3.选中数据库:
use tutorial;
4.建表:
CREATETABLE users;
查看表:
mysql> show tables
-> ;
+--------------------+
| Tables_in_tutorial |
+--------------------+
| users |
+--------------------+
1 row in set (0.00 sec)
5.查询信息:
select * from users;
mysql> select * from users;
+----+------+-----------+
| id | name | email |
+----+------+-----------+
| 1 | cy | cy@qq.com |
+----+------+-----------+
1 row in set (0.00 sec)
6.或者使用本地sql文件建表:
mysql> use tutorial;
Database changed
mysql> source /var/www/html/tutorial/schemas/tutorial.sql;
7.现实数据库XXX所拥有的表:
mysql> show tables;
+-------------------------+
| Tables_in_GoodByeDealer |
+-------------------------+
| dict_band |
| dict_car_item |
| dict_car_item_value |
| dict_car_style |
| dict_country |
| dict_order_service |
| dict_pic_pos |
| dict_state |
| tb_address |
| tb_car_detail |
| tb_car_pic |
| tb_car_simple |
| tb_order |
| tb_pay_detail |
| tb_user |
+-------------------------+
15 rows in set (0.00 sec)