MySQL 数据库迁移到PostgreSQL上(最新)

首先你需要有一个独立的Pyhton虚拟环境,我使用的是conda

本工具只能在pyhton2.6,python2.7 运行

conda create -n mysql2pgsql python=2.7 -y

进入虚拟环境 conda activate mysql2pgsql

git clone git://github.com/philipsoutham/py-mysql2pgsql.git

cd py-mysql2pgsql

yum install python-devel mysql-devel

python setup.py install 

安装成功后执行 py-mysql2pgsql

会生成一个配置mysql2pgsql.yml

编辑 vi mysql2pgsql.yml

mysql:
 hostname: localhost
 port: 3306
 socket: /var/lib/mysql/mysql.sock     (/etc/my.cnf)
 username: root
 password: ******
 database: db_name
 compress: false
destination:
 # if file is given, output goes to file, else postgres
 file:
 postgres:
  hostname: localhost
  port: 5431
  username: postgres
  password: postgres
  database: db_name

# if tables is given, only the listed tables will be converted.  leave empty to convert all tables.
#only_tables:
#- d_evalyaosudata
#- table2
# if exclude_tables is given, exclude the listed tables from the conversion.
#exclude_tables:
#- d_evalyaosudata
#- table4

编辑完后 在pg 里创建你要迁移的数据库注意表不能含有中文备注,否则回报错误:

UnicodeEncodeError: 'latin-1' codec can't encode character

然后执行 py-mysql2pgsql -v -f mysql2pgsql.yml 

 

 

你可能感兴趣的:(linux)