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. 分享知识-快乐自己:都说新的Arraylist 扩容是(1.5倍+1) 看了1.8的源代码发现不是这么回事

    都说新的Arraylist 扩容是(1.5倍+1) 看了1.8的源代码发现不是这么回事 就用下面这段代码在jdk的三个版本运行看了下效果: import java.lang.reflect.Field ...

  2. 解决:夜神模拟器连不上adb的问题

    一. adb devices发现不了设备 刚试了一下,在夜神模拟器开启的情况下,adb devices 死活找不到设备 adb kill-server和adb start-server也无济于事 二. ...

  3. 使用cqlsh远程连接cassandra——设置cassandra.yaml里rpc_address和listen_address为ipv4地址即可

    You need to edit cassandra.yaml on the node you are trying to connect to and set the node ip address ...

  4. 【lightoj-1026】Critical Links(桥)

    题意: 给出无向图,求桥的模板题. #include <bits/stdc++.h> using namespace std; ; int dfn[N], low[N];//时间戳;low ...

  5. react use simditor

    1.install simditor 2.import simditor && scss import $ from "jquery" import Simdito ...

  6. 201621123003《Java程序设计》第一周学习总结

    #1. 本周学习总结 本周主要学习了Java的jdk.jvm.jre等基本概念,Java的发展史,知道Java语言的跨平台.面向对象等主要特点,简单了解了Java程序的编译和运行过程.对于学习Java ...

  7. Js中分号使用总结

    作者:尤雨溪链接:https://www.zhihu.com/question/20298345/answer/49551142来源:知乎著作权归作者所有,转载请联系作者获得授权. 没有应该不应该,只 ...

  8. [置顶] Android App引导页这些坑你自己犯过吗?

    场景:测试机:华为荣耀6x 今天我自己掉入一个很蠢蠢的坑,一个引导页搞了20多分钟,不管我怎么测试用真机还是模拟器都无法运行,但是我写的demo完全没问题,好无语,我都怀疑我是不是搞android,我 ...

  9. GO语言打包ICO图标

    1. go get github.com/akavel/rsrc2. 创建manifest文件, 命名:main.exe.manifest : <?xml version="1.0&q ...

  10. 当导用模块与包的import与from的问题(模块与包的调用)

    当在views.py里写impor models会不会报错呢? 1.Python里面的py文件都是每一行的代码. 2.Python解释器去找一个模块的时候,只去sys.path的路径里找 3.djan ...