数据库安装
1.1安装前准备
系统参数:
服务器
IP地址 192.168.31.173
数据库版本 8.0.28
端口号 3306
字符集 UTF-8
安装前配置:
[root@~]# yum install openssl openssl-devel
[root@~]# rpm -e mariadb-libs –nodeps
1.2安装数据库
解压安装数据库
[root@~]# tar -xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
[root@~]# rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm
[root@~]# rpm -ivh mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
[root@~]# rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm
[root@~]# rpm -ivh mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm
[root@~]# rpm -ivh mysql-community-devel-8.0.28-1.el7.x86_64.rpm
[root@~]# rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm
[root@~]# rpm -ivh mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
[root@~]# rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm
启动数据库服务
[root@~]# systemctl start mysqld
查看数据库root用户初始密码
[root@~]# cat /var/log/mysqld.log|grep password
2准备测试数据
2.1创建数据库对象
DROP DATABASE IF EXISTS employees;
CREATE DATABASE employees;
USE employees;
DROP TABLE IF EXISTS dept_emp,dept_manager,titles,salaries,employees,departments;
CREATE TABLE employees (
emp_no INT NOT NULL,
birth_date DATE NOT NULL,
first_name VARCHAR(14) NOT NULL,
last_name VARCHAR(16) NOT NULL,
gender ENUM ('M','F') NOT NULL,
hire_date DATE NOT NULL,
PRIMARY KEY (emp_no)
);
CREATE TABLE departments (
dept_no CHAR(4) NOT NULL,
dept_name VARCHAR(40) NOT NULL,
PRIMARY KEY (dept_no),
UNIQUE KEY (dept_name)
);
CREATE TABLE dept_manager (
emp_no INT NOT NULL,
dept_no CHAR(4) NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
FOREIGN KEY (dept_no) REFERENCES departments (dept_no) ON DELETE CASCADE,
PRIMARY KEY (emp_no,dept_no)
);
CREATE TABLE dept_emp (
emp_no INT NOT NULL,
dept_no CHAR(4) NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
FOREIGN KEY (dept_no) REFERENCES departments (dept_no) ON DELETE CASCADE,
PRIMARY KEY (emp_no,dept_no)
);
CREATE TABLE titles (
emp_no INT NOT NULL,
title VARCHAR(50) NOT NULL,
from_date DATE NOT NULL,
to_date DATE,
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
PRIMARY KEY (emp_no,title, from_date)
);
CREATE TABLE salaries (
emp_no INT NOT NULL,
salary INT NOT NULL,
from_date DATE NOT NULL,
to_date DATE NOT NULL,
FOREIGN KEY (emp_no) REFERENCES employees (emp_no) ON DELETE CASCADE,
PRIMARY KEY (emp_no, from_date)
);
CREATE OR REPLACE VIEW dept_emp_latest_date AS
SELECT emp_no, MAX(from_date) AS from_date, MAX(to_date) AS to_date
FROM dept_emp
GROUP BY emp_no;
CREATE OR REPLACE VIEW current_dept_emp AS
SELECT l.emp_no, dept_no, l.from_date, l.to_date
FROM dept_emp d
INNER JOIN dept_emp_latest_date l
ON d.emp_no=l.emp_no AND d.from_date=l.from_date AND l.to_date = d.to_date;
2.2导入测试数据
source load_departments.dump ;
source load_employees.dump ;
source load_dept_emp.dump ;
source load_dept_manager.dump ;
source load_titles.dump ;
source load_salaries1.dump ;
source load_salaries2.dump ;
source load_salaries3.dump ;
select 'employees',count(1) from employees
union all
select 'departments',count(1) from departments
union all
select 'dept_manager',count(1) from dept_manager
union all
select 'dept_emp',count(1) from dept_emp
union all
select 'titles',count(1) from titles
union all
select 'salaries',count(1) from salaries;
3数据迁移
3.1迁移前准备
3.1.1迁移参数
3.1.2配置MySQL用户允许其他服务器远程连接
update user set host = '%' where user='root';
flush privileges;
3.1.3达梦数据库创建对应用户
CREATE TABLESPACE "EMPLOYEES" DATAFILE 'EMPLOYEES.DBF' SIZE 128 AUTOEXTEND ON
NEXT 2048;
CREATE USER "EMPLOYEES" IDENTIFIED BY "Dameng@1234" DEFAULT TABLESPACE "EMPLOYEES" DEFAULT INDEX TABLESPACE "EMPLOYEES";
GRANT "PUBLIC","RESOURCE","VTI","SOI" TO "EMPLOYEES";
3.1.4修改达梦数据库兼容参数
修改dm.ini文件
COMPATIBLE_MODE = 4
重启数据库服务
3.2 数据迁移
3.2.1新建迁移
3.2.2选择迁移方式
3.2.3选择MySQL连接
3.2.4选择达梦连接
3.2.5选择需要迁移的模式(MySQL库对应达梦的模式,现在保持对象名大小写)
3.2.6选择迁移对象
3.2.7显示迁移概要
3.2.8迁移完成
3.3迁移数据对比
3.3.1新建数据比对
3.3.2创建MySQL连接
3.3.3.创建达梦连接
3.3.4选择对比模式
3.3.5选择对比对象/参数
3.3.6查看对比任务
3.3.7执行对比任务
3.3.8查看对比报错问题
1.对比MySQL和达梦的表发现表索引的名字不同,功能相同。
2.对比MySQL和达梦视图发现视图功能一致,写法不同。
MySQL
CREATE OR REPLACE VIEW dept_emp_latest_date AS
SELECT emp_no, MAX(from_date) AS from_date, MAX(to_date) AS to_date
FROM dept_emp
GROUP BY emp_no;
达梦
CREATE VIEW "EMPLOYEES"."dept_emp_latest_date" ("emp_no","from_date","to_date")
AS
select "dept_emp"."emp_no" AS "emp_no",max("dept_emp"."from_date") AS "from_date",max("dept_emp"."to_date") AS "to_date" from "dept_emp" group by "dept_emp"."emp_no";
3.3.9查看对比结果概述
4.迁移问题
4.1数据对比客户端
数据对比DTS的客户端需要新版本的,老版本的客户端没有数据对比的功能。这个只需要安装做对比的客户端DTS是新版本的,数据库系统是老版本的没有问题。
文章
阅读量
获赞