原文链接:
https://blog.csdn.net/wjlwangluo/article/details/78165588
安装
Ubuntu下安装常规软件都比较简单,直接使用apt-get即可。安装步骤如下:
输入mysql命令
系统会提示没有安装这个软件,如下图:
$ sudo apt-get install mysql-client-core-5.6
$ sudo apt-get install mariadb-client-core-10.0
之后安装Server部分
$ sudo apt-get install mysql-server
安装过程中会提示设置root密码,注意设置了不要忘了,安装完成之后可以使用如下命令来检查是否安装成功:
$ sudo netstat -tap | grep mysql
通过上述命令检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功。
登陆mysql数据库
可以通过如下命令:
$ mysql -u root -p
$ mysql -h localhost -u root -p
-u 表示选择登陆的用户名
-p 表示登陆的用户密码
-h 登录主机名
服务启动、停止
1. 启动方式
1、使用 service 启动:
service mysql start
2、使用 mysqld 脚本启动
/etc/inint.d/mysql start
3、使用 safe_mysqld 启动
safe_mysql&
查看mysql是否在监听端口命令
$netstat -tl | grep mysql
会看到如下类似内容
tcp 0 0 *:mysql *:* LISTEN
2. 停止
1、使用 service 启动
service mysql stop
2、使用 mysqld 脚本启动
/etc/inint.d/mysql stop
3、mysqladmin shutdown
3. 重启
1、使用 service 启动
service mysql restart
2、使用 mysqld 脚本启动
/etc/inint.d/mysql restart
数据类型
MySQL有三大类数据类型, 分别为数字、日期\时间、字符串, 这三大类中又更细致的划分了许多子类型:
1. 数字类型
整数:
tinyint、smallint、mediumint、int、bigint
浮点数:
float、double、real、decimal
日期和时间:
date、time、datetime、timestamp、year
2. 字符串类型
字符串:
char、varchar
文本:
tinytext、text、mediumtext、longtext
二进制(可用来存储图片、音乐等):
tinyblob、blob、mediumblob、longblob
常用命令
create database new_dbname;--新建数据库
drop database old_dbnane; --删除数据库
show databases;--显示数据库
use databasename;--使用数据库
select database();--查看已选择的数据库
show tables;--显示当前库的所有表
create table tablename(fieldname1 fieldtype1,fieldname2 fieldtype2,..)[ENGINE=engine_name];--创建表
drop table tablename; --删除表
create table tablename select statement;--通过子查询创建表
desc tablename;--查看表结构
show create table tablename;--查看建表语句
alter table tablename add new_fielname new_fieldtype;--新增列
alter table tablename add new_fielname new_fieldtype after 列名1;--在列名1后新增列
alter table tablename modify fieldname new_fieldtype;--修改列
alter table tablename drop fieldname;--删除列
alter table tablename_old rename tablename_new;--表重命名
insert into tablename(fieldname1,fieldname2,fieldnamen) valuse(value1,value2,valuen);--增
delete from tablename [where fieldname=value];--删
update tablename set fieldname1=new_value where filename2=value;--改
select * from tablename [where filename=value];--查
truncate table tablename;--清空表中所有数据,DDL语句
show engines;--查看mysql现在已提供的存储引擎:
show variables like '%storage_engine%';--查看mysql当前默认的存储引擎
show create table tablename;--查看某张表用的存储引擎(结果的"ENGINE="部分)
alter table tablename ENGINE=InnoDB--修改引擎
create table tablename(fieldname1 fieldtype1,fieldname2 fieldtype2,..) ENGINE=engine_name;--创建表时设置存储引擎
通过脚本文件操作:
mysql -D samp_db -u root -p < createtable.sql
在mysql网站中下载mysql workbench
https://dev.mysql.com/downloads/workbench/
到本地之后
sudo dpkg -i mysql-workbench-community_8.0.15-1ubuntu18.04_amd64.deb
报错
Selecting previously unselected package mysql-workbench-community.
(Reading database ... 216034 files and directories currently installed.)
Preparing to unpack mysql-workbench-community-6.3.10-1ubuntu16.04-amd64.deb ...
Unpacking mysql-workbench-community (6.3.10-1ubuntu16.04) ...
dpkg: dependency problems prevent configuration of mysql-workbench-community:
mysql-workbench-community depends on libgeos-c1v5 (>= 3.4.2); however:
Package libgeos-c1v5 is not installed.
mysql-workbench-community depends on libhdf4-0-alt; however:
Package libhdf4-0-alt is not installed.
mysql-workbench-community depends on libmysqlclient20 (>= 5.7.11); however:
Package libmysqlclient20 is not installed.
mysql-workbench-community depends on libnetcdf11 (>= 4.0.1); however:
Package libnetcdf11 is not installed.
mysql-workbench-community depends on libpcrecpp0v5 (>= 7.7); however:
Package libpcrecpp0v5 is not installed.
mysql-workbench-community depends on libpq5; however:
Package libpq5 is not installed.
mysql-workbench-community depends on libxerces-c3.1; however:
Package libxerces-c3.1 is not installed.
mysql-workbench-community depends on libzip4 (>= 0.10); however:
Package libzip4 is not installed.
mysql-workbench-community depends on python-paramiko (>= 1.15.1); however:
Package pyth
dpkg: error processing package mysql-workbench-community (--install):
dependency problems - leaving unconfigured
Processing triggers for shared-mime-info (1.5-2ubuntu0.1) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...
Errors were encountered while processing:
mysql-workbench-community
然后执行
sudo apt install libgeos-c1v5 libhdf4-0-alt libmysqlclient20 libnetcdf11 libpcrecpp0v5 libpq5 libxerces-c3.1 libzip4 python-paramiko
继续报错
skh@skh-vm:~/Downloads$ sudo apt-get install libpq5
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
mysql-workbench-community : Depends: libgeos-c1v5 (>= 3.4.2) but it is not going to be installed
Depends: libhdf4-0-alt but it is not going to be installed
Depends: libmysqlclient20 (>= 5.7.11) but it is not going to be installed
Depends: libnetcdf11 (>= 4.0.1) but it is not going to be installed
Depends: libpcrecpp0v5 (>= 7.7) but it is not going to be installed
Depends: libxerces-c3.1 but it is not going to be installed
Depends: libzip4 (>= 0.10) but it is not going to be installed
Depends: python-paramiko (>= 1.15.1) but it is not going to be installed
Depends: python-crypto but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
根据提示,执行如下命令:
sudo apt-get -f install
然后再执行安装:
sudo dpkg -i mysql-workbench-community-6.3.10-1ubuntu16.04-amd64.deb