MYSQL数年库安装
MySQL系列
MySQL 的三大主要分支
mysql
mariadb
percona Server
MySQL系列
2.2.2.1 MySQL 的三大主要分支
mysql
mariadb
percona Server
官方文档
https://dev.mysql.com/doc/
https://mariadb.com/kb/en/
https://www.percona.com/software/mysql-database/percona-server
版本演变
MySQL:5.1 --> 5.5 --> 5.6 --> 5.7 -->8.0
MariaDB:5.5 -->10.0--> 10.1 --> 10.2 --> 10.3 --> 10.4 --> 10.5
MYSQL的特性
插件式存储引擎:也称为“表类型”,存储管理器有多种实现版本,功能和特性可能均略有差别;用
户可根据需要灵活选择,Mysql5.5.5开始innoDB引擎是MYSQL默认引擎
MyISAM ==> Aria
InnoDB ==> XtraDB
单进程,多线程
诸多扩展和新特性
提供了较多测试组件
开源
RPM包安装MySQL
CentOS 安装光盘
项目官方:https://downloads.mariadb.org/mariadb/repositories/
国内镜像:https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/
https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/
CentOS 8:安装光盘直接提供
mysql-server:8.0
mariadb-server : 10.3.17
CentOS 7:安装光盘直接提供
mariadb-server:5.5 服务器包
| mariadb CentOS 6: |
客户端工具包 |
| mysql-server:5.1 服务器包 | |
| mysql | 客户端工具包 |
初始化脚本提高安全性
运行脚本:mysql_secure_installation
设置数据库管理员root口令
禁止root远程登录
删除anonymous用户帐号
删除test数据库
MySQL 组成
客户端程序
设置数据库管理员root口令
禁止root远程登录
删除anonymous用户帐号
删除test数据库
mysql: 交互式的CLI工具
mysqldump:备份工具,基于mysql协议向mysqld发起查询请求,并将查得的所有数据转换成
insert等写操作语句保存文本文件中
mysqladmin:基于mysql协议管理mysqld
mysqlimport:数据导入工具
MyISAM存储引擎的管理工具:
myisamchk:检查MyISAM库
myisampack:打包MyISAM表,只读
服务器端程序
mysqld_safemysqld
mysqld_multi 多实例 ,
示例:mysqld_multi --example
用户账号
mysql用户账号由两部分组成:
'USERNAME'@'HOST
说明:
HOST限制此用户可通过哪些远程主机连接mysql服务器
支持使用通配符:
% 匹配任意长度的任意字符
172.16.0.0/255.255.0.0 或 172.16.%.%
_ 匹配任意单个字符
mysql 客户端命令
mysql 运行命令类型
客户端命令:本地执行,每个命令都完整形式和简写格式
服务端命令:通过mysql协议发往服务器执行并取回结果,命令末尾都必须使用命令结束符号,默
认为分号
mysql 使用模式
交互模式
脚本模式:
mysql> \h, help
mysql> \u,use
mysql> \s,status
mysql> \!,system
mysql -uUSERNAME -pPASSWORD < /path/somefile.sql
cat /path/somefile.sql | mysql -uUSERNAME -pPASSWORD
mysql>source /path/from/somefile.sql
mysql命令使用格式
mysql客户端常用选项:
登录系统:
运行mysql命令:
范例:mysql的配置文件,修改提示符
mysql -uUSERNAME -pPASSWORD < /path/somefile.sql
cat /path/somefile.sql | mysql -uUSERNAME -pPASSWORD
mysql>source /path/from/somefile.sql
mysql [OPTIONS] [database]
-A, --no-auto-rehash 禁止补全
| -u, --user= -h, --host= |
用户名,默认为root 服务器主机,默认为localhost |
| -p, --passowrd= 用户密码,建议使用-p,默认为空密码 | |
| -P, --port= | 服务器端口 |
| -S, --socket= -D, --database= -C, --compress |
指定连接socket文件路径 指定默认数据库 启用压缩 |
| -e “SQL“ | 执行SQL命令 |
| -V, --version -v --verbose --print-defaults |
显示版本 显示详细信息 获取程序默认使用的配置 |
运行mysql命令
mysql>use mysql
mysql>select user(); #查看当前用户
mysql>SELECT User,Host,Password FROM user;
MYSQL配置文件修命令提示符
查看mysql版本
[root@centos8 ~]#mysql -V
mysql Ver 15.1 Distrib 10.3.11-MariaDB, for Linux (x86_64) using readline 5.1
#临时修改mysql提示符
[root@centos8 ~]#mysql -uroot -pcentos --prompt="\\r:\\m:\\s(\\u@\\h) [\\d]>\\_"
#临时修改mysql提示符
[root@centos8 ~]#export MYSQL_PS1="\\r:\\m:\\s(\\u@\\h) [\\d]>\\_"
#持久修改mysql提示符
[root@centos8 ~]#vim /etc/my.cnf.d/mysql-clients.cnf
[mysql]
prompt="\\r:\\m:\\s(\\u@\\h) [\\d]>\\_"
mysql --print-defaults -v
mysql would have been started with the following arguments:
--prompt=\r:\m:\s(\u@\h) [\d]>\_ -v
[root@centos8 ~]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.3.11-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
10:29:30(root@localhost) [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
10:29:34(root@localhost) [mysql]> exit
[root@centos8 ~]#cat /etc/my.cnf.d/mysql-clients.cnf
#
# These groups are read by MariaDB command-line tools
# Use it for options that affect only one utility
#
[mysql]
prompt="\\r:\\m:\\s> "
user=root
password=centos
配置客户端mysql的自动登录
vim/etc/my.cnf.d/client.conf
[client]
user=root
password=centos
mysqladmin命令
mysqladmin 命令格式
范例:
[root@centos8 ~]#mysql --print-defaults -v
mysql would have been started with the following arguments:
--prompt=\r:\m:\s(\u@\h) [\d]>\_ -v
[root@centos8 ~]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.3.11-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
10:29:30(root@localhost) [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
10:29:34(root@localhost) [mysql]> exit
[root@centos8 ~]#cat /etc/my.cnf.d/mysql-clients.cnf
#
# These groups are read by MariaDB command-line tools
# Use it for options that affect only one utility
#
[mysql]
prompt="\\r:\\m:\\s> "
user=root
password=centos
vim/etc/my.cnf.d/client.conf
[client]
user=wang
password=centos
mysqladmin [OPTIONS] command command....2.4.4.5 服务器端配置
服务器端(mysqld):工作特性有多种配置方式
1、命令行选项:
2、配置文件:类ini格式,集中式的配置,能够为mysql的各应用程序提供配置信息
服务器端配置文件:
配置文件格式:
[mysqld]
[mysqld_safe]
[mysqld_multi]
[mysql]
[mysqldump]
[server]
[client]
格式:parameter = value
说明:_和- 相同
1,ON,TRUE意义相同, 0,OFF,FALSE意义相同
2.4.4.6 socket地址
服务器监听的两种socket地址:
ip socket: 监听在tcp的3306端口,支持远程通信 ,侦听3306/tcp端口可以在绑定有一个或全部接
口IP上
unix sock: 监听在sock文件上,仅支持本机通信, 如:/var/lib/mysql/mysql.sock)
说明:host为localhost 时自动使用unix sock
2.4.4.7 关闭mysqld网络连接
只侦听本地客户端, 所有客户端和服务器的交互都通过一个socket文件实现,socket的配置存放
在/var/lib/mysql/mysql.sock) 可在/etc/my.cnf修改
范例:
#查看mysql服务是否正常,如果正常提示mysqld is alive
mysqladmin -uroot -pcentos ping
#关闭mysql服务,但mysqladmin命令无法开启
mysqladmin -uroot -pcentos shutdown
#创建数据库testdb
mysqladmin -uroot -pcentos create testdb
#删除数据库testdb
mysqladmin -uroot -pcentos drop testdb
#修改root密码
mysqladmin -uroot -pcentos password magedu’
#日志滚动,生成新文件/var/lib/mysql/mariadb-bin.00000N
mysqladmin -uroot -pcentos flush-logs
mysqladmin 命令格式
范例:
[root@centos8 ~]#mysql --print-defaults -v
mysql would have been started with the following arguments:
--prompt=\r:\m:\s(\u@\h) [\d]>\_ -v
[root@centos8 ~]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.3.11-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
10:29:30(root@localhost) [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
10:29:34(root@localhost) [mysql]> exit
[root@centos8 ~]#cat /etc/my.cnf.d/mysql-clients.cnf
#
# These groups are read by MariaDB command-line tools
# Use it for options that affect only one utility
#
[mysql]
prompt="\\r:\\m:\\s> "
user=root
password=centos
vim/etc/my.cnf.d/client.conf
[client]
user=wang
password=centos
mysqladmin [OPTIONS] command command....
服务器端配置
服务器端(mysqld):工作特性有多种配置方式
1、命令行选项:
2、配置文件:类ini格式,集中式的配置,能够为mysql的各应用程序提供配置信息
服务器端配置文件:
配置文件格式:
[mysqld]
[mysqld_safe]
[mysqld_multi]
[mysql]
[mysqldump]
[server]
[client]
格式:parameter = value
说明:_和- 相同
1,ON,TRUE意义相同, 0,OFF,FALSE意义相同
2.4.4.6 socket地址
服务器监听的两种socket地址:
ip socket: 监听在tcp的3306端口,支持远程通信 ,侦听3306/tcp端口可以在绑定有一个或全部接
口IP上
unix sock: 监听在sock文件上,仅支持本机通信, 如:/var/lib/mysql/mysql.sock)
说明:host为localhost 时自动使用unix sock
2.4.4.7 关闭mysqld网络连接
只侦听本地客户端, 所有客户端和服务器的交互都通过一个socket文件实现,socket的配置存放
在/var/lib/mysql/mysql.sock) 可在/etc/my.cnf修改
范例:
#查看mysql服务是否正常,如果正常提示mysqld is alive
mysqladmin -uroot -pcentos ping
#关闭mysql服务,但mysqladmin命令无法开启
mysqladmin -uroot -pcentos shutdown
#创建数据库testdb
| mysqladmin -uroot -pcentos #删除数据库testdb mysqladmin -uroot -pcentos #修改root密码 |
create testdb |
| drop testdb |
mysqladmin -uroot -pcentos password magedu’
#日志滚动,生成新文件/var/lib/mysql/mariadb-bin.00000N
mysqladmin -uroot -pcentos flush-logs
服务器端配置
服务器端(mysqld):工作特性有多种配置方式
1、命令行选项:
2、配置文件:类ini格式,集中式的配置,能够为mysql的各应用程序提供配置信息
服务器端配置文件:
配置文件格式:
[mysqld]
[mysqld_safe]
[mysqld_multi]
[mysql]
[mysqldump]
[server]
[client]
格式:parameter = value
说明:_和- 相同
1,ON,TRUE意义相同, 0,OFF,FALSE意义相同
2.4.4.6 socket地址
服务器监听的两种socket地址:
ip socket: 监听在tcp的3306端口,支持远程通信 ,侦听3306/tcp端口可以在绑定有一个或全部接
口IP上
unix sock: 监听在sock文件上,仅支持本机通信, 如:/var/lib/mysql/mysql.sock)
说明:host为localhost 时自动使用unix sock
2.4.4.7 关闭mysqld网络连接
只侦听本地客户端, 所有客户端和服务器的交互都通过一个socket文件实现,socket的配置存放
在/var/lib/mysql/mysql.sock) 可在/etc/my.cnf修改
范例:
#查看mysql服务是否正常,如果正常提示mysqld is alive
mysqladmin -uroot -pcentos ping
#关闭mysql服务,但mysqladmin命令无法开启
mysqladmin -uroot -pcentos shutdown
#创建数据库testdb
mysqladmin -uroot -pcentos create testdb
#删除数据库testdb
mysqladmin -uroot -pcentos drop testdb
#修改root密码
mysqladmin -uroot -pcentos password magedu’
#日志滚动,生成新文件/var/lib/mysql/mariadb-bin.00000N
mysqladmin -uroot -pcentos flush-logs
/etc/my.cnf #Global选项
/etc/mysql/my.cnf #Global选项
~/.my.cnf #User-specific 选项2.5 通用二进制格式安装 MySQL
2.5.1 准备用户
2.5.2 准备数据目录,建议使用逻辑卷
2.5.3 准备二进制程序
2.5.4 准备配置文件
2.5.5 创建数据库文件
vim /etc/my.cnf
[mysqld]
skip-networking=1
准备用户
roupadd -r -g 306 mysql
useradd -r -g 306 -u 306 -d /data/mysql mysql
准备数据目录,建议使用逻辑卷
#可选做,后面的脚本mysql_install_db可自动生成此目录
mkdir /data/mysql
chown mysql:mysql /data/mysql
准备二进制程序
tar xf mariadb-VERSION-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -sv mariadb-VERSION mysql
chown -R root:root /usr/local/mysql/
准备配置文件
cd /usr/local/mysql
cp -b support-files/my-large.cnf /etc/my.cnf
vim /etc/my.cnf
#mysql语句块中添加以下三个选项
[mysqld]
datadir = /data/mysql
innodb_file_per_table = on #在mariadb5.5以上版的是默认值,可不加
skip_name_resolve = on #禁止主机名解析,建议使用
创建数据库文件
cd /usr/local/mysql/
./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
[root@centos8 mysql]#ls /data/mysql/ -l
total 110604
-rw-rw---- 1 mysql mysql 12582912 Jun 1 16:44 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Jun 1 16:44 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Jun 1 16:44 ib_logfile1
drwx------ 2 mysql mysql 4096 Jun 1 16:44 mysql
drwx------ 2 mysql mysql 4096 Jun 1 16:44 performance_schema
drwx------ 2 mysql mysql 4096 Jun 1 16:44 test
准备服务脚本,并启动服务
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start
#如果有对应的service 文件可以执行下面
cp support-files/systemd/mariadb.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl enable --now mariadb
PATH路径
echo 'PATH=/user/local/mysql/bin:$PATH’ > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
安全初始化
/user/local/mysql/bin/mysql_secure_installation
MYSQL数年库安装的更多相关文章
- debian系列下c++调用mysql, linux下面安装mysql.h文件
mysql.h的报错还没有解决,你们不用看了,等我解决了吧还不知道什么时候 先用c吧 #include <stdio.h> #include <stdlib.h> #inclu ...
- CentOS 6.9上安装Mysql 5.7.18 安装
CentOS 6.9上安装Mysql 5.7.18 安装 下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-g ...
- Dubbo入门到精通学习笔记(十九):MySQL源码编译安装、MySQL主从复制的配置
文章目录 MySQL 源码编译安装(CentOS-6.6+MySQL-5.6) 一.服务器配置: 二.源码安装 MySQL5.6.26: MySQL主从复制的配置 环境 依赖课程 MySQL 主从复制 ...
- Mysql多实例数据库安装应用
第1章 MySQL多实例数据库企业级应用实践 1.1 MySQL多实例介绍 前文已经讲了为什么选择MySQL数据库,以及MySQL数据库在Linux系统下的多种安装方式,同时以单实例讲解了编译方式安装 ...
- MySQL的下载与安装 和 navicat for mysql 安装使用
新手上路-MySQL安装 目录结构 Windows平台 MySQL安装 示例数据导入 Linux平台 CentOS系统 Ubuntu系统 FAQ 密码生成工具-keepass 修改提示符 图形工具 删 ...
- MySQL 高可用MHA安装部署以及故障转移详细资料汇总 转
http://blog.itpub.net/26230597/cid-87082-list-2/ 1,简介 .1mha简介 MHA,即MasterHigh Availability Manager a ...
- CentOS下MySQL 5.7编译安装
CentOS下MySQL 5.7编译安装 文章目录 安装依赖包 下载相应源码包 添加mysql用户 预编译 编译安装 启动脚本,设置开机自启动 /etc/my.cnf,仅供参考 初始化数据库 设置 ...
- 应用mysql(Linux中安装)
当前 mysql 官网的安装教程,指明可以使用 yum 方式. 若在Ubuntu中安装,参考“Linux(Ubuntu)下MySQL的安装与配置”. MySQL YUM Repository MySQ ...
- linux下mysql的卸载、安装全过程
卸载mysql 1.查找以前是否装有mysql 命令:rpm -qa|grep -i mysql 可以看到mysql的两个包: mysql-4.1.12-3.RHEL4.1 mysqlclient10 ...
随机推荐
- CentOS下搭建自动化测试基础框架:Jenkins+Maven+TestNG+ReportNG
1. 安装JDK 1.1 卸载系统默认已安装的open-jdk rpm -qa|grep java 查出来openjdk相关的应用,把查出来的所有都要通过下面的命令给卸载掉 rpm -e --node ...
- Java反射使用方法
//简单的例子public class ReflextionMain { public static void main(String[] args) throws ClassNotFoundExce ...
- Elementui【tooltip】 在弹框关闭之后再次‘出现’的问题
如图,第一次弹窗进来的时候,符合条件之后,这个提示文字的位置是对的,而且正常显示: 现在点击取消按钮,第二次进入弹窗,如图,提示文字就跑到了左上角,而且输入符合条件的数值之后,会另外显示一个toolt ...
- SQL注入的原理及一般步骤
原理 SQL注入是一种攻击方式,在这种攻击方式中,恶意代码被插入到字符串中,然后该字符串传递到SQL Server的实例以进行分析和执行.任何构成SQL语句的过程都应进行注入检查,因为SQL Serv ...
- iOS数据持久化方式及class_copyIvarList与class_copyPropertyList的区别
iOS数据持久化方式:plist文件(属性列表)preference(偏好设置)NSKeyedArchiver(归档)SQLite3CoreData沙盒:iOS程序默认情况下只能访问自己的程序目录,这 ...
- MySql索引分析及查询优化
B-Tree 核心特点: 多路,非二叉树 每个节点既保存索引,又保存数据 搜索时相当于二分查找 B+Tree 核心特点 多路非二叉 只有叶子节点保存数据 搜索时相当于二分查找 增加了相邻接点的指向指针 ...
- nginx负载均衡中利用redis解决session一致性问题
关于session一致性的现象及原因不是本小作文的重点,可以另行找杜丽娘O(∩_∩)O哈哈~重点是利用redis集中存储共享session的实际操作. 一.业务场景:nginx/tomcat/redi ...
- Dapr 助力应用架构的可持续性
在文章亚马逊可持续软件工程实践[1] 有这么一段我们为什么要关注"可持续发展": 联合国于 2015 年制定了一个全球框架<巴黎协定>[2],随后各缔约国纷纷制定了&q ...
- NSSCTF-[SWPU 2019]Network
下载附件打开之后发现是和ascii比较像,但是尝试解码发现不是ascii,然后这里问了一下大佬然后又翻了一下自己的笔记,最后发现是TTL,这里直接上脚本, import binascii with o ...
- VBS病毒实验
实验目的 探讨VBS病毒实现原理,为更好的深入防御和查杀病毒 实验原理 VBS病毒发生机理 实验内容 编写简单VBS病毒,并实现功能,学习VBS病毒发生机理 实验环境描述 VPC1(虚拟PC) 操作系 ...