数据库升级与回滚

397 阅读1分钟

升级 数据库 使用 cinder 用户


su -s /bin/sh -c 'cinder-manage db sync' cinder

降级 数据库

生产环境 杜绝 使用, 但是 开发过程中 难免 需要 回滚 错误的版本 来 还原 环境


 select * from migrate_version;
+---------------+--------------------------------------------------------------------+---------+
| repository_id | repository_path                                                    | version |
+---------------+--------------------------------------------------------------------+---------+
| cinder        | /usr/lib/python2.7/site-packages/cinder/db/sqlalchemy/migrate_repo |      87 |
+---------------+--------------------------------------------------------------------+---------+

update migrate_version set version=86;


-- 修改代码后  再次进行 升级
su -s /bin/sh -c 'cinder-manage db sync' cinder
cat /var/log/cinder/cinder-manage.log

查询 表 中 所有 字段


table_name    表名称
table_schema  数据库名称

# 只查询   字段名称
select CONCAT(COLUMN_NAME ,',') from information_schema.COLUMNS where table_name = 'clusters' and table_schema = 'clusters';


# 查询 字段 名称 以及 类型  与 长度
select COLUMN_NAME, DATA_TYPE , CHARACTER_MAXIMUM_LENGTH from information_schema.COLUMNS where table_name = 'clusters' ;

# 查询 字段 所有属性
select * from information_schema.COLUMNS where table_name = 'clusters' ;


su 使用


Usage:
 su [options] [-] [USER [arg]...]

Change the effective user id and group id to that of USER.
A mere - implies -l.   If USER not given, assume root.

Options:
 -m, -p, --preserve-environment  do not reset environment variables
 -g, --group <group>             specify the primary group
 -G, --supp-group <group>        specify a supplemental group

 -, -l, --login                  make the shell a login shell
 -c, --command <command>         pass a single command to the shell with -c
 --session-command <command>     pass a single command to the shell with -c
                                 and do not create a new session
 -f, --fast                      pass -f to the shell (for csh or tcsh)
 -s, --shell <shell>             run shell if /etc/shells allows it

 -h, --help     display this help and exit
 -V, --version  output version information and exit