1 官网下载,链接  https://www.mysql.com/downloads/

Download MySQL Community Server

默认为你选好了Mac OS X 平台

选择的是.dmg的。点击右侧的download进行下载。

跳转到另外一个界面,提示你需不需要注册,直接选择最下面的“No thanks,just take me to downloads!”

 安装MySQL

安装完成后终端输入:

$mysql -version

-bash: mysql: command not found

”/usr/local/mysql/bin/mysql”为mysql默认安装路径:

$/usr/local/mysql/bin/mysql -version

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

$cd /usr/local/bin

$sudo ln -fs  /usr/local/mysql/bin/mysql  mysql

Password:

$mysql  -version

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

配置root账号的密码,默认没有配置,

$ mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql>update mysql.user  set  authentication_string = password('******') where user ='root';

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;

mysql> quit

flush privileges后mysql -u root就登录不上了,需要用密码了例如下面

$mysql -u root

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database homework;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

出现这样的报错,解决办法:重新设置一遍密码

mysql> set password =password('******');

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> create database homework;

Query OK, 1 row affected (0.00 sec)

mysql> use homework;

Database changed

mysql> show tables;

Empty set (0.00 sec)

数据库的基本操作,创建数据库。

mysql> create table Student(Sno int(10),Sname varchar(255),Ssex varchar(255),Sage int(10),Sdept varchar(255));

Query OK, 0 rows affected (0.03 sec)

mysql> show tables;

+--------------------+

| Tables_in_homework |

+--------------------+

| Student            |

+--------------------+

1 row in set (0.00 sec)

查看创建表的信息语句:

mysql> show create table Student;

+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Table   | Create Table                                                                                                                                                                                                                              |

+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Student | CREATE TABLE `Student` (

`Sno` int(10) DEFAULT NULL,

`Sname` varchar(255) DEFAULT NULL,

`Ssex` varchar(255) DEFAULT NULL,

`Sage` int(10) DEFAULT NULL,

`Sdept` varchar(255) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1 |

+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.02 sec)

mysql> create table Course(Con int(10),Cname varchar(255),Cpno int(10),Ccredit int(10));

Query OK, 0 rows affected (0.03 sec)

mysql> show create table Course;

+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Table  | Create Table                                                                                                                                                                                      |

+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Course | CREATE TABLE `Course` (

`Con` int(10) DEFAULT NULL,

`Cname` varchar(255) DEFAULT NULL,

`Cpno` int(10) DEFAULT NULL,

`Ccredit` int(10) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1 |

+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

插入一条数据:

mysql> insert into Course values('4','data structure','7','4');

Query OK, 1 row affected (0.00 sec)

更新一条数据:

mysql> update Course set Cno='5' where Cname='data structure';

ERROR 1054 (42S22): Unknown column 'Cno' in 'field list'

发现创建的字段应该是Cno,创建错了,成Con

更改字段:

mysql> alter table Course change Con Cno int(10);

Query OK, 0 rows affected (0.02 sec)

Records: 0  Duplicates: 0  Warnings: 0

mysql> update Course set Cno='5' where Cname='data structure';

Query OK, 1 row affected (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 0

查询数据:

mysql> select * from Course;

+------+--------------------+------+---------+

| Cno  | Cname              | Cpno | Ccredit |

+------+--------------------+------+---------+

|    1 | database           |    5 |       4 |

|    2 | math               |    0 |       2 |

|    3 | information system |    1 |       4 |

|    4 | operation  system  |    6 |       3 |

|    5 | data structure     |    7 |       4 |

|    6 | data process       |    0 |       2 |

|    7 | pascal             |    6 |       4 |

+------+--------------------+------+---------+

7 rows in set (0.00 sec)

												

mysql安装及基本操作(mysql作业)的更多相关文章

  1. MYSQL安装与基本操作

    http://docs.sqlalchemy.org/en/latest/    sqlalchemy文档 1.下载,下载版本太多,不知道下哪个好,别人介绍版本 进入官网-->点击最下面 DOW ...

  2. ubuntu linux mysql 安装 基本操作 命令

    mysql --help #如果有信息证明系统已经安装了mysql mysql -V #查看版本号 netstat -tap|grep mysql #检查mysql是否在启动状态 卸载mysql: s ...

  3. MySQL安装之后没有MySQL数据库的原因

    mysql安装完之后,登陆后发现只有两个数据库:mysql> show databases;+--------------------+| Database           |+------ ...

  4. Linux下eclipse及mysql安装,c++访问mysql数据库

    这两天在学习linux下用c++访问mysql,碰到一堆问题,记录一下. 1.mysql安装: 公司的电脑是64位的,安装的是64为的RHEL4,安装如下三个包: MySQL-client-5.1.4 ...

  5. Day1 MySql安装和基本操作

    数据和数据库 1.数据:客观事物的符号表示. 2.存储介质:纸,光盘,磁盘,u盘,云盘… 3.存储的目的:检索(查询) 存储数据量加大,导致检索的难度升高. 4.数据库(DB:database):按照 ...

  6. Mysql安装后打开MySQL Command Line Client闪退解决方法

    1.开始菜单下;Mysql--->mysql server 5.6-->mysql command line Client ---右击,选择属性 2.在属性下查看目标位置: 3.将安装目录 ...

  7. heidsql(mysql)安装教程和mysql修改密码

    简单介绍安装 官网下载:https://mariadb.org/download/ 直接下载(mariadb-10.3.9-winx64.msi):https://github.com/weibang ...

  8. mysql 安装为服务 ,mysql.zip 安装为服务,mysql搬移迁移服务器安装为服务

    从服务器A打包到服务器B后,在服务器B中运行安装服务命令,可自定义服务名,一台服务器上可装N个MySql实例 mysqld --install MySQL_0001 --defaults-file=D ...

  9. Ubuntu 15 下 Qt 配置mysql链接及基本操作

    序 最近需要在Linux下做一个unix网络编程项目,选择了Ubuntu 最新版本15.04 : 开发环境:Qt 5 数据库: MySQL 安装Qt 和 MySQL 简要介绍一下软件的安装! 安装Qt ...

随机推荐

  1. tomcat映射物理路径

    <Context path="/woyoubaoweb/upload" docBase="/opt/file/image/woyoubaoweb/upload&qu ...

  2. 初识Linux(五)--VI/VIM编辑器

    我们操作文件,终究离不开编辑文件,对文件内容的编辑,Linux系统下,我们通常使用VI/VIM来编辑文件.VI是每个Linux都会自带的文本编辑器,VIM是VI的增强版,可能有些发行版本没有自带,可以 ...

  3. 理解 EventLoop

    链接 链接 node 浏览器 执行顺序有差异 macrotask microtask 一个线程会有 堆 栈 消息队列;  栈函数执行是用的, 堆用了存放定义的对象, 消息队列来处理异步的操作 a() ...

  4. C#模拟网络POST请求

    using System; using System.IO; using System.Net; using System.Text; using System.Collections.Generic ...

  5. QA,敢问路在何方?听听微软资深QA怎么说~

    转载地址:http://blog.csdn.net/ocean1ee/article/details/8905031 我已经从事测试工作超过7年,从测试员(SDET)成长为高级测试员(SDET II) ...

  6. TCP服务器端口数,最大连接数以及MaxUserPort的关系辨真

    原文连接:http://www.jianshu.com/p/4a58761d758f 关于TCP服务器最大并发连接数有一种误解就是"因为端口号上限为65535,所以TCP服务器理论上的可承载 ...

  7. canvas 创建渐变图形

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. unity 事件顺序及功能说明

    unity3d中所有控制脚本的基类MonoBehaviour有一些虚函数用于绘制中事件的回调,也可以直接理解为事件函数,例如大家都很清楚的Start,Update等函数,以下做个总结. Awake 当 ...

  9. linux 系统监控某目录下文件及文件夹的变化

    inotifywait 是一个可以实时监控文件变动的工具,它利用linux内核中的inotify机制实现监控功能. 查看内核版本 [root@Oracle ~]# uname -r 2.6.32-22 ...

  10. HDU - 6116:路径计数 (组合数&NTT)

    一个包含四个点的完全图,可以在任意节点出发,可以在任意节点结束,给出每个点被经过的次数,求有多少种合法的遍历序列.如果两个序列至少有一位是不同的,则认为它们不相同. Input 2 3 3 3 Sam ...