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 ...
随机推荐
- Go-gin CORS 跨域中间件
原文:https://stackoverflow.com/questions/29418478/go-gin-framework-cors func CORSMiddleware() gin.Hand ...
- Eclipse中Preference打开后找不到Server项解决方案。
该解决方案是假设你已经安装好了JDK,tomcat,eclipse,突然在Eclipse的配置时找不到选择菜单栏中的window——preferences-server——runtime enviro ...
- Go语言实现FastDFS分布式存储系统WebAPI网关
前言 工作需要,第一次使用 Go 来实战项目. 需求:采用 golang 实现一个 webapi 的中转网关,将一些资源文件通过 http 协议上传至 FastDFS 分布式文件存储系统. 一.Fas ...
- QT延时方法
(转自:http://blog.sina.com.cn/s/blog_613cfe940100kacm.html) 1. void sleep(unsigned int msec){ QTime ...
- Android性能优化系列总篇
目前性能优化专题已完成以下部分: 性能优化总纲——性能问题及性能调优方式 性能优化第四篇——移动网络优化 性能优化第三篇——Java(Android)代码优化 性能优化第二篇——布局优化 性能优化第一 ...
- Slice header里面有哪些重要的参数?
first_mb_in_slice:第一个宏块在slice的位置 slice_type:slice的类型 pic_parameter_set_id:slice对应的pps的id frame_num:表 ...
- 深入浅出Eclipse Modeling Framework (EMF)
Eclipse Modeling Framework (EMF),简单的说,就是Eclipse提供的一套建模框架,可以用EMF建立自己的UML模型,设计模型的XML格式或编写模型的java代码.EMF ...
- zoj-3963 Heap Partition(贪心+二分+树状数组)
题目链接: Heap Partition Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A sequence ...
- Games Delphi developers play
Original link: Games Delphi developers play Delphi game developers are stupid people having too ma ...
- 旧书重温:0day2【9】第六章 攻击c++的虚函数
不知不觉,我们学到了0day2的第六章形形色色的内存攻击技术!其中,这张很多东西都是理论的东西,不过!我们还是要想办法还原下发生的现场! 其中部分文章截图 http://user.qzone.qq.c ...