mysql入门

安装

su root
yum install mysql-server
yum install mysql
yum install mysql-devel

启动sql服务器

/etc/init.d/mysqld restart
如果是在非root环境用下面的命令即可
sudo service mysqld start;

用户登陆

mysql -u用户名 -p密码;
mysql -uroot -proot;

创建数据库并使用

mysql> create database bigdb;
Query OK, 1 row affected (0.01 sec)

mysql> use bigdb;
Database changed

mysql> show tables;
Empty set (0.00 sec)

查看存储引擎

mysql> show engines;
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)

创建表

mysql> create table brand(
    -> bid varchar(9) not null,
    -> category varchar(10) not null,
    -> shop varchar(8) not null) 
    -> engine=innodb 
    -> default charset=utf8;
Query OK, 0 rows affected (0.01 sec)

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

mysql> show create table brand;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                             |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| brand | CREATE TABLE `brand` (
  `bid` varchar(9) NOT NULL,
  `category` varchar(10) NOT NULL,
  `shop` varchar(8) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> 

导入表

## 错误示例1 ##
mysql> load data infile '/home/bigdata/datasource/brand.list'
    -> into table brand 
    -> fields terminated by ','
    -> lines terminated by '¥n';
ERROR 13 (HY000): Can't get stat of '/home/bigdata/datasource/brand.list' (Errcode: 13)

## 错误示例2 ##
mysql> load local  data infile '/home/bigdata/datasource/brand.list'
    -> into table brand 
    -> fields terminated by ','
    -> lines terminated by '¥n';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'local  data infile '/home/bigdata/datasource/brand.list'
into table brand 
field' at line 1

## 正确示例 ##
mysql> load data local infile '/home/bigdata/datasource/brand.list'
    -> into table brand 
    -> fields terminated by ','
    -> lines terminated by '\n';
Query OK, 1000 rows affected, 87 warnings (0.00 sec)
Records: 1000  Deleted: 0  Skipped: 0  Warnings: 87
mysql> 

mysql> select * from brand limit 5;
+----------+-----------+----------+
| bid      | category  | shop     |
+----------+-----------+----------+
| 00000000 | telephone | OPPO     |
| 00000001 | computer  | ASUS     |
| 00000002 | sports    | MIZUNO   |
| 00000003 | sports    | LINING   |
+----------+-----------+----------+
5 rows in set (0.00 sec)

mysql> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值