mysql安装及基本操作(mysql作业)
1 官网下载,链接 https://www.mysql.com/downloads/
Download MySQL Community Server
默认为你选好了Mac OS X 平台
选择的是.dmg的。点击右侧的download进行下载。
跳转到另外一个界面,提示你需不需要注册,直接选择最下面的“No thanks,just take me to downloads!”
2 安装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作业)的更多相关文章
- MYSQL安装与基本操作
http://docs.sqlalchemy.org/en/latest/ sqlalchemy文档 1.下载,下载版本太多,不知道下哪个好,别人介绍版本 进入官网-->点击最下面 DOW ...
- ubuntu linux mysql 安装 基本操作 命令
mysql --help #如果有信息证明系统已经安装了mysql mysql -V #查看版本号 netstat -tap|grep mysql #检查mysql是否在启动状态 卸载mysql: s ...
- MySQL安装之后没有MySQL数据库的原因
mysql安装完之后,登陆后发现只有两个数据库:mysql> show databases;+--------------------+| Database |+------ ...
- Linux下eclipse及mysql安装,c++访问mysql数据库
这两天在学习linux下用c++访问mysql,碰到一堆问题,记录一下. 1.mysql安装: 公司的电脑是64位的,安装的是64为的RHEL4,安装如下三个包: MySQL-client-5.1.4 ...
- Day1 MySql安装和基本操作
数据和数据库 1.数据:客观事物的符号表示. 2.存储介质:纸,光盘,磁盘,u盘,云盘… 3.存储的目的:检索(查询) 存储数据量加大,导致检索的难度升高. 4.数据库(DB:database):按照 ...
- Mysql安装后打开MySQL Command Line Client闪退解决方法
1.开始菜单下;Mysql--->mysql server 5.6-->mysql command line Client ---右击,选择属性 2.在属性下查看目标位置: 3.将安装目录 ...
- heidsql(mysql)安装教程和mysql修改密码
简单介绍安装 官网下载:https://mariadb.org/download/ 直接下载(mariadb-10.3.9-winx64.msi):https://github.com/weibang ...
- mysql 安装为服务 ,mysql.zip 安装为服务,mysql搬移迁移服务器安装为服务
从服务器A打包到服务器B后,在服务器B中运行安装服务命令,可自定义服务名,一台服务器上可装N个MySql实例 mysqld --install MySQL_0001 --defaults-file=D ...
- Ubuntu 15 下 Qt 配置mysql链接及基本操作
序 最近需要在Linux下做一个unix网络编程项目,选择了Ubuntu 最新版本15.04 : 开发环境:Qt 5 数据库: MySQL 安装Qt 和 MySQL 简要介绍一下软件的安装! 安装Qt ...
随机推荐
- 委托,lambda,匿名方法
lambda表达式其实就是匿名方法的变体或者说简写. 原来我们用 delegate void Del(int x); Del d = delegate(int x) { return x + 1; } ...
- http Code含义
5xx - 服务器错误 服务器由于遇到错误而不能完成该请求.
- Redis 有序集合(sorted set),发布订阅,事务,脚本,连接,服务器(三)
Redis 有序集合(sorted set) Redis 有序集合和集合一样也是string类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个double类型的分数.redis正是通过 ...
- openvswitch的原理和常用命令
一.Openvswitch工作原理 openvSwitch是一个高质量的.多层虚拟交换机,使用开源Apache2.0许可协议,由 Nicira Networks开发,主要实现代码为可移植的C代码.它的 ...
- Struts07---访问servlet的API
01.创建登录界面 <%@ page language="java" import="java.util.*" pageEncoding="UT ...
- react antd layout sider
import React from 'react'; import {Link, withRouter} from 'react-router-dom'; import {Layout, Menu, ...
- 用函数式编程,从0开发3D引擎和编辑器(一)
介绍 大家好,欢迎你踏上3D编程之旅- 本系列的素材来自我们的产品:Wonder-WebGL 3D引擎和编辑器 的整个开发过程,探讨了在从0开始构建3D引擎和编辑器的过程中,每一个重要的功能点.设计方 ...
- 测试中认识 sqlite
1.SQLite,是一款轻型的数据库:简单, 轻松的API 单词速记中单词离线包也用到sqlite 百度了一下,基本的使用语句: .help .quit sqlite3 testDB.db 在当前目录 ...
- I.MX6 Android 设备节点权限
/********************************************************************************** * I.MX6 Android ...
- 如何在公司Http代理后使用NuGet官方源
文章转自CSDN 霍力强的专栏 有些公司上网使用的是Http代理.默认情况下,VS是无法访问外部网络的.如果要使用NuGet,通常只能在局域网里架一个自己的NuGet服务器.但这种方法不论是packa ...