linux下mysql安装与使用!

下载与安装

采用命令:sudo apt-get install mysql-server-5.6进行下载与安装,按Y继续。
linux下mysql安装与使用!
在输入两次密码后安装成功!

本地连接数据库

采用命令连接mysql数据库。示例连接root用户数据库:
[email protected]:~$ mysql -u root –p
Enter password:******
连接成功显示如下字段:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.6.33-0ubuntu0.14.04.1 (Ubuntu)
Copyright © 2000, 2016, 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>

连接成功后即可对数据库进行基本操作

1.show databases;//显示
linux下mysql安装与使用!
2.use mysql;//选择数据库,进入mysql数据库
linux下mysql安装与使用!
3.create database 数据库名;//创建数据库
linux下mysql安装与使用!
4.drop database 数据库名;//删除数据库
linux下mysql安装与使用!
5.create table 表名();//创建数据表
linux下mysql安装与使用!
6.drop table 表名;//删除数据表
linux下mysql安装与使用!
7.insert into 表名(field1,field2,…fieldn)
values
(value1,value2,…valuen);
//向表中插入数据
linux下mysql安装与使用!
8.select * from 表名 [where 条件];//查询数据
(1)查询表中所有,更改*即可更改查询内容linux下mysql安装与使用!
(2)使用where 条件查询linux下mysql安装与使用!
9.updata 表名 set 更改的内容 where 条件;//更改表中的数据内容
linux下mysql安装与使用!
linux下mysql安装与使用!
10.delect from 表名 where 条件;//删除数据表中的数据
linux下mysql安装与使用!
linux下mysql安装与使用!

采用Workbench连接数据库

安装后打开:
linux下mysql安装与使用!
问题一:在测试连接的过程中出现10061的错误,解决办法如下:
linux下mysql安装与使用!
linux下mysql安装与使用!
问题二:出现如下提示:
linux下mysql安装与使用!
查找原因如下:在下图的用户表中我们能看到,root用户是只允许本地登录的。
因此存在两种解决方案,1.更改root的权限,2.创建其他用户数据库进行操作(不建议对root进行更改),在实际的开发应用中一般也不对root进行更改。
linux下mysql安装与使用!
因此我们采用命令create user ‘admin’@’%’ identified ‘123456’;
创建一个admin的用户后采用workbench进行连接:
linux下mysql安装与使用!
连接成功!
在对admin这个用户的数据库操作时,存在很多的权限不够的情况,我们可以相应的给予它一些权限。
grant update on mysql.* to ‘admin’@‘%’;//给admin这个用户在mysql数据库上能进行update即更新数据的能力。
grant all privileges on . to ‘admin’@’%’;//给admin这个用户所有的权力