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 ...
随机推荐
- spring3: AOP 之代理机制
Spring AOP通过代理模式实现,目前支持两种代理:JDK动态代理.CGLIB代理来创建AOP代理,Spring建议优先使用JDK动态代理. JDK动态代理:使用java.lang.reflect ...
- 通过Google Custom Search API 进行站内搜索
今天突然想把博客的搜索改为google的站内搜索,印象中google adsense中好像提高这个站内搜索的代码,但苦逼的是google adsense帐号一直审核不通过,所以只能通过google c ...
- Win10/Server2016镜像集成离线补丁
Win10镜像集成离线补丁 因为正常安装系统后再打补丁比较漫长,可以事先做好打过补丁的iso,备将来使用. 以管理员身份运行cmd,然后通过dism提取.挂载.集成补丁.保存install.wim镜像 ...
- Ant Design
https://ant.design/components/form-cn/ (Ant Design of React 中文网) 1.Ant Design of react (相关资料) htt ...
- DOCKER实战案例
操作系统:[root@yz6205 ~]# docker search busyboxNAME DESCRIPTION STARS OFFICIAL AUTOMATEDbusybox Busybox ...
- react-webpack(二)
const path = require('path'); const webpack = require('webpack'); const HtmlWebpackPlugin = require( ...
- 【PL/SQL编程】注释说明
1. 单行注释 由两个连接字符“--”开始,后面紧跟着注释内容. 2. 多行注释 由/*开头, 由*/结尾.
- padding和margin的用法
在CSS中margin是指从自身边框到另一个容器边框之间的距离,就是容器外距离.在CSS中padding是指自身边框到自身内部另一个容器边框之间的距离,就是容器内距离. 一.padding 1.语法结 ...
- 解决Net内存泄露原因
Net内存泄露原因及解决办法 https://blog.csdn.net/changtianshuiyue/article/details/52443821 什么是.Net内存泄露 (1).NET 应 ...
- 接口测试基础——第4篇logging模块
Logging:日志记录是为了跟踪记录软件运行时,发生的事件,包括出错,提示信息等等. log日志级别:日志级别大小关系为:CRITICAL > ERROR > WARNING > ...