SQL基础应用--DDL(数据库定义语言)应用

  • 基于Centos7.6

1.库定义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1>建库
create database school;
create schema sch;
show charset;
show collation;
CREATE DATABASE test CHARSET utf8;
create database xyz charset utf8mb4 collate utf8mb4_bin;

建库规范:
1.库名不能有大写字母
2.建库要加字符集
3.库名不能有数字开头
4.库名要和业务相关

建库标准语句
mysql> create database db charset utf8mb4; #还可以加校对规则如:create database db charset utf8mb4 collate utf8mb4_bin;
mysql> show create database db;

2>删库(生产中禁止使用)
mysql> drop database database_name;

3>修改
SHOW CREATE DATABASE school;
ALTER DATABASE school CHARSET utf8;
注意:修改字符集,修改后的字符集一定是原字符集的严格超集(从小的往大的改,如utf8-->utf8mb4),否则可能出现乱码

4>查询
show databases;
show create database database_name;

Read More

SQL基础应用--数据类型、表属性、字符集

  • 基于Centos7.6

1.数据类型

​ 1>作用
​ 保证数据的准确性和标准性。

Read More

SQL基础应用--SQL介绍、SQL分类、数据库逻辑结构

  • 基于Centos7.6

1.SQL介绍

1
结构化查询语言,关系型数据库通用的查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统。MySQL5.7 以后遵循SQL92标准,通过sql_mode参数来控制。

Read More

MariaDB10.5.8配置Keepalived

  • 基于Ubuntu20.04.01

1.主、备节点分别安装

1
2
3
apt-cache search keepalived
keepalived - Failover and monitoring daemon for LVS clusters
apt-get install keepalived

Read More

MariaDB10.5.8支持中文方法

  • 基于Ubuntu20.04.01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
vim /etc/mysql/mariadb.conf.d/50-client.cnf
#(MySQL为该路径:/etc/my.cnf.d/client.cnf) 文件,添加如下内容

[client]

default-character-set=utf8

vim /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf
#(MySQL为该路径:/etc/my.cnf.d/mysql-clients.cnf)文件,添加如下内容

[mysql]
default-character-set=utf8

vim /etc/mysql/mariadb.cnf
#(MySQL为该路径:/etc/my.cnf) 文件,添加如下内容

[mysqld]
character-set-server=utf8
default-storage-engine=INNODB

•重启服务

# systemctl restart mariadb

Read More

MariaDB10.5.8配置主主模式

  • 基于Ubuntu20.04.01

1.主备机分别修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
vim /etc/mysql/mariadb.cnf

#主机备份原文件,清空之前配置,改为如下内容:
[mysqld]
datadir=/var/lib/mysql
socket=/run/mysqld/mysqld.sock
server-id=1
log-bin=mysql-bin
relay-log=mysql-relay-bin
auto_increment_offset=1
auto_increment_increment=2
log_slave_updates =1
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=performance_schema.%
slave-skip-errors=all


备机备份原文件,清空之前配置,改为如下内容:
[mysqld]
datadir=/var/lib/mysql
socket=/run/mysqld/mysqld.sock
server-id=2
log-bin=mysql-bin
relay-log=mysql-relay-bin
auto_increment_offset=2
auto_increment_increment=2
log_slave_updates =1
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=performance_schema.%
slave-skip-errors=all

Read More

MySQL5.7基础管理--多实例应用

  • 基于Centos7.6

1.准备多个目录

1
mkdir -p /data/330{7,8,9}/data

Read More

MySQL5.7基础管理--连接管理、内置功能、初始化配置

  • 基于Centos7.6

1.连接管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1>MySQL命令连接
#注意提前应该将用户授权做好
两种连接方式:
(1)TCP/IP方式:
格式: mysql -u用户名 -p -h 登录IP -P端口
#如果登录端口号为默认的3306可以不加-P3306,但使用-h必须配合-P,否则使用'mysql -u用户名 -P'格式是本地socket方式登录。
例子: mysql -uroot -p -h 10.0.0.50 -P3306
远程登录会在线程中显示为远程模式登录:
mysql> show processlist;
+----+------+---------------------+------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+---------------------+------+---------+------+----------+------------------+
| 4 | test | 192.168.3.187:56216 | NULL | Query | 0 | starting | show processlist |
+----+------+---------------------+------+---------+------+----------+------------------+
1 row in set (0.00 sec)
#如果同时出现远程与socket方式登录,会优先使用远程登录。如:mysql -uroot -p -S /tmp/mysql.sock -h 10.0.0.50 -P3306
(2)Socket方式:
格式: mysql -u用户名 -p -S socket文件路径
例子: mysql -uroot -p -S /tmp/mysql.sock

2> 客户端工具连接
如SQLyog、Navicat等

Read More

Redhat8.3在线安装MariaDB

  • 基于Redhat8.3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
yum erase podman buildah
sudo dnf -y update
sudo dnf module install mariadb
#检查安装情况
rpm -qi mariadb-server
sudo systemctl enable --now mariadb
mysql_secure_installation
#初始化过程
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
… Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
… Success!

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y

Dropping test database…
… Success!
Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
… Success!

Cleaning up…

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

mysql -uroot -p
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

Read More

Redhat8.3在线安装Docker

  • 基于Redhat8.3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1.确认是否有旧版本docker。有的话卸载
yum list installed | grep docker (查询)
yum remove -y docker-ce.x86_64 docker-client.x86_64 docker-common.x86_64(卸载)
2.安装需要的依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
yum install -y epel-release
3.添加阿里云库
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4.安装插件
dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.4.3-3.1.el7.x86_64.rpm
#更换环境如果报错缺失某个containerd.io版本,可以到连接中更换版本地址在线安装
5.安装docker
yum install -y docker-ce
6.启动docker并检测:
systemctl start docker.service
docker version
systemctl status docker
systemctl enable docker.service(开机启动)

-----------------------------------------
1.安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
2.更改权限
chmod +x /usr/local/bin/docker-compose
3.查看版本
docker-compose --version

Read More