mysql> create database puyangDB;
一、安装mysql
下载地址:mysql-5.7.19-macos10.12-x86_64.dmg
二、配置 path
PodLine:~ podmac$ vim .bash_profile
export PATH=$PATH:/usr/local/mysql-5.7.19-macos10.12-x86_64/bin
使配置文件生效
source ~/.bash_profile
三、修改root 密码
启动mysql ,在系统偏好设置里 启动mysql
//登录mysql
mysql> mysql -u root -p
mysql> set password for root@localhost = password('111111');
四、查看mysql的信息
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.7.13, for osx10.11 (x86_64) using EditLine wrapper
Connection id: 927
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.19 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 30 min 39 sec
Threads: 1 Questions: 19 Slow queries: 0 Opens: 106 Flush tables: 1 Open tables: 99 Queries per second avg: 0.010
--------------
mysql>
五、查看版本
5.1、方式1
PodLine:~ podmac$ mysql --help | grep Distrib
5.2.方式2
PodLine:~ podmac$ mysql -V
mysql Ver 14.14 Distrib 5.7.13, for osx10.11 (x86_64) using EditLine wrapper
5.3 方式3
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.19 |
+-----------+
1 row in set (0.00 sec)
mysql>
六、库操作
6.1 创建数据库
命令:create database <数据库名>
例如:建立一个名为puyangDB的数据库
6.2 显示所有的数据库
命令:show databases (注意:最后有个s)
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| puyangDB |
| sys |
+--------------------+
5 rows in set (0.01 sec)
6.3 删除数据库
命令:drop database <数据库名>
mysql> drop database puyangDB;
6.4 连接数据库
命令: use <数据库名>
mysql> use puyangDB;
Database changed
mysql>
6.5 查看当前使用的数据库
mysql> select database();
+------------+
| database() |
+------------+
| puyangdb |
+------------+
1 row in set (0.00 sec)
mysql>
6.6 当前数据库包含的表信息:
mysql> show tables;
Empty set (0.00 sec)
mysql>
参考文献 http://www.cnblogs.com/hateislove214/archive/2010/11/05/1869889.html